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.

4

1 回答 1

2

请务必记住,RStudio Server(开源版本)不会在登录 shell 下运行用户会话。因此,当您su - rstudiobash 启动时,您将获得初始化的 shell 变量。

值得庆幸的是,有一个非常简单的方法可以解决这个问题:符号链接 R_HOME/etc/Renviron.site(请参阅R 初始化)到/etc/environment. R 的环境文件具有与 Linux 相同的格式(即 KEY=VALUE),因此您可以为 R 和 bash 提供相同的环境初始值设定项列表。

于 2016-02-29T17:57:56.190 回答