2

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.

cryo111
  • 4,444
  • 1
  • 15
  • 37

1 Answers1

2

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.

Jonathan
  • 8,497
  • 41
  • 35
  • Great! Actually, I have thought that this problem is so specific that it's very unlikely to get an answer. But today was my lucky day as it seems. :) Since everything works fine with the regular R version, I guess that Revolution (or Microsoft) has changed something in the start-up procedures. Anyhow, just in case someone is interested, here the command that creates the link `sudo ln -s /etc/environment /usr/lib64/MRO-3.2.3/R-3.2.3/lib/R/etc/Renviron.site`. One might have to change the last path to one's specific MRO installation path, though. – cryo111 Feb 29 '16 at 18:47
  • OMG, completely forgot that I had already code that reads and processes `/etc/environment` in `R_HOME/etc/Rprofile.site` for regular R. So, riddle solved: MRO has another `Rprofile.site` file where I did not set these variables. But I will keep @Jonathan's solution as it is much cleaner and easier. – cryo111 Feb 29 '16 at 19:18