You can run R sessions under a program supervisor that modifies their environment or available resources. You can specify a supervisor (and the arguments which control it’s behavior) using the
rsession-exec-command setting in
/etc/rstudio/rserver.conf. See customizing session launches for more information.
Example use case
RStudio Server Pro allows you to select from multiple versions of R from within the IDE. If you set certain environment variables in your
.bash_profile you may get undesirable results in RStudio Server Pro. It is possible to select one version of R in RStudio Server Pro but load a different version based on your
LD_LIBRARY_PATH environment variable in particular may cause the incorrect version of R to start up inside RStudio Server Pro.
For example, a user may select R-3.2.4 from the drop down menu in RStudio Server Pro, but the
LD_LIBRARY_PATH in the
.bash_profile might specifiy R-3.2.1. If the
.bash_profile prepends the batch version such that
LD_LIBRARY_PATH=/batch/R/path/R-3.2.1:$LD_LIBRARY_PATH then RStudio Server Pro will attempt to load R-3.2.1 in the session even though R-3.2.4 was selected.
Example program supervisor
The solution is to configure RStudio Server Pro so that it overrides a specific set of environment variables. This can be done by customizing session launces as described in the admin guide. This approach basically requires the administrator to create a new file that will be executed prior to any new session being started. It involves the following steps.
Step 1. Identify the environment variables to be overridden
Let’s say this is your user’s
.bash_profile. Notice that it is designed to launch R-3.2.1 in batch mode and exports three environment varialbes
R_HOME_BATCH=/opt/R/R-3.2.1/lib64/R LD_LIBRARY_PATH=$R_HOME_BATCH/lib:$LD_LIBRARY_PATH PATH=$R_HOME_BATCH/bin:$PATH MANPATH=$R_HOME_BATCH/share:$MANPATH export PATH MANPATH LD_LIBRARY_PATH
Step 2. Write a new script to overwrite the environment variables
Create a new script called
/etc/rstudio/rsession-run.sh that will prepend
R_HOME to the environment variables in step 1 whenever RStudio Server Pro executes a new session. Make sure to execute the R session at the end by including
#!/bin/bash LD_LIBRARY_PATH=$R_HOME/lib:$LD_LIBRARY_PATH PATH=$R_HOME/bin:$PATH MANPATH=$R_HOME/share:$MANPATH export MANPATH PATH LD_LIBRARY_PATH exec $@
Step 3. Make the script an executible.
chmod 755 /etc/rstudio/rsession-run.sh
Step 4. Tell RStudio Server Pro to execute the new script
Next, configure RStudio Server Pro so that it will run the new script. This can be done by pointing the
rsession-exec-command option in the
/etc/rstudio/rserver.conf to the new script.
Step 5. Restart RStudio Server Pro