I am running RStudio Server (0.99.879) on Amazon EC2 and have recently updated to Microsoft R Open 3.2.3 (formerly Revolution R). All software runs on Ubuntu 14.04.
Since I wanted to have my Amazon access keys available in all shell sessions for all users, I have put them in /etc/environment
like AWS_ACCESS_KEY=123
.
RStudio runs under user rstudio
which I have checked via executing system("whoami")
in RStudio. Before switching to Microsoft R Open [MRO], system("echo $AWS_ACCESS_KEY")
(executed from RStudio) gave the correct result 123
. But now it returns an empty string.
However, if I switch to user rstudio
in the console via su - rstudio
and start MRO from the shell, system("echo $AWS_ACCESS_KEY")
gives the correct result, which really puzzles me.
It seems as if only RStudio together with MRO makes R forget the environment variables defined in etc/environment
.
Do you guys know what could be the reason for this strange behavior? Any pointers to possible fixes?
I would really like to keep the keys in just one place (which is /etc/environment
) and definitely not hard coded in my R code. One fix that I could think of is to read /etc/environment
from R, extract the AWS_ACCESS_KEY
and set it via Sys.setenv()
. But this is mostly just a hack and I would like to understand what the real problem is...
BTW: Maybe I should mention that I had to change the R_HOME_DIR
variable in the R start script /usr/bin/R
to R_HOME_DIR=/usr/lib64/MRO-3.2.3/R-3.2.3/lib/R
because the code that was determining the home directory before did not work with MRO.
It's important to keep in mind that RStudio Server (the open source edition) does not run user sessions under a login shell. So when you su - rstudio
, you're getting the shell variables that are initialized when bash starts.
Thankfully there's a pretty easy way around this: symlink R_HOME/etc/Renviron.site
(see R initialization) to /etc/environment
. R's environment files have the same format as Linux's (i.e. KEY=VALUE), so you can supply the same list of environment initializers to both R and bash.