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 Workbench (previously 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 Workbench. It is possible to select one version of R in RStudio Workbench but load a different version based on your .bash_profile
. The LD_LIBRARY_PATH
environment variable in particular may cause the incorrect version of R to start up inside RStudio Workbench.
For example, a user may select R-3.2.4 from the drop down menu in RStudio Workbench, but the LD_LIBRARY_PATH
in the .bash_profile
might specify 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 Workbench 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 Workbench so that it overrides a specific set of environment variables. This can be done by customizing session launches 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 variables LD_LIBRARY_PATH
, PATH
, and MANPATH
.
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 Workbench executes a new session.
#!/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
Step 3. Make the script an executable.
chmod 755 /etc/rstudio/rsession-run.sh
Step 4. Tell RStudio Workbench to execute the new script
Next, configure RStudio Workbench 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.
rsession-exec-command=source /etc/rstudio/rsession-run.sh
Step 5. Restart RStudio Workbench
rstudio-server restart
Comments