diff --git a/template/script.sh.erb b/template/script.sh.erb
index 04442ea6c278448a97fc2930132c52d57be04f37..2e0e135bf9c3ad025c98f1c5977134f39466952e 100755
--- a/template/script.sh.erb
+++ b/template/script.sh.erb
@@ -1,8 +1,6 @@
 #!/usr/bin/env bash
 module reset
 
-<%= context.custom_environment %>
-
 # load RStudio Server
 module load <%= context.rstudio_version %>
 
@@ -21,12 +19,19 @@ export RSESSION_WRAPPER_FILE="${PWD}/rsession.sh"
 (
 umask 077
 sed 's/^ \{2\}//' > "${RSESSION_WRAPPER_FILE}" << EOL
-  #!/usr/bin/env bash
+  #!/bin/bash -l
 
   # Log all output from this script
   export RSESSION_LOG_FILE="${PWD}/rsession.log"
   exec &>>"\${RSESSION_LOG_FILE}"
 
+  # load R
+  module load <%= context.r_version %>
+
+  <%= context.custom_environment %>
+
+  module list
+
   # Launch the original command
   echo "Launching rsession..."
   set -x