Rstudio-server environment variables not loading?

16,776

Solution 1

You should set your environment variables in .Renviron or Renviron.site. I think these files are defined under R_HOME/etc/Renviron.site. You can get more information by typing:

> ?Startup

Someone had a similar issue here and this is what he did to solve it.

Solution 2

Note that on Windows, R looks for the .Renviron file in /Users/<name>/Documents, while RStudio appears to expect the .Renviron file to be in /Users/<name>/.

Share:
16,776

Related videos on Youtube

AI52487963
Author by

AI52487963

Updated on June 04, 2022

Comments

  • AI52487963
    AI52487963 almost 2 years

    I'm trying to run rhadoop on Cloudera's hadoop distro (I can't remember if its CDH3 or 4), and am running into an issue: Rstudio server doesn't seem to recognize my global variables.

    In my /etc/profile.d/r.sh file, I have:

    export HADOOP_HOME=/usr/lib/hadoop
    export HADOOP_CONF=/usr/hadoop/conf
    export HADOOP_CMD=/usr/bin/hadoop
    export HADOOP_STREAMING=/usr/lib/hadoop-mapreduce/
    

    When I run R from the terminal, I get:

    > Sys.getenv("HADOOP_CMD")
    [1] "usr/bin/hadoop"
    

    But when I run Rstudio server:

    > Sys.getenv("HADOOP_CMD")
    [1] ""
    

    And as a result, when I try to run rhdfs:

    > library("rJava", lib.loc="/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15")
    > library("rhdfs", lib.loc="/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15")
    Error : .onLoad failed in loadNamespace() for 'rhdfs', details: 
        call: fun(libname, pkgname)
        error: Environment variable HADOOP_CMD must be set before loading package rhdfs
    Error: package/namespace load failed for 'rhdfs'
    

    Does anyone know where I should be putting my enviornment variables if not in that specific r.sh file?

    Thanks!

  • AI52487963
    AI52487963 almost 11 years
    Hmm...I added HADOOP_CMD="/usr/bin/hadoop" to my ~/.Rprofile , but that didn't seem to do the trick. Rstudio server still gives a "" result for Sys.getenv("HADOOP_CMD").
  • user1609452
    user1609452 almost 11 years
    Worked for me I added SOMEVAR = /somepath to /usr/lib/R/etc/Renviron. R.home() = "/usr/lib/R". I restarted RStudio and Sys.getenv('SOMEVAR') correctly found the variable.
  • AI52487963
    AI52487963 almost 11 years
    Sorry, I'm new to rstudio-server and can't seem to figure out where the Renviron profile would sit. In /usr/lib/ I only have rstudio-server and subfolders bin, extras, R, resources, and www. Is there a recommended spot to start an Renviron file in?
  • James Tobin
    James Tobin about 10 years
    btw that 'here' link is currently outdated and I agree with @AI52487963 that the ?Startup documentation is not very helpful for people new to rstudio-server
  • FvD
    FvD over 9 years
    This is an effective way to solve path issues, but please note that the correct syntax would be Sys.setenv(HADOOP_CMD="/path/to/hadoop").
  • FXQuantTrader
    FXQuantTrader over 8 years
    In case it helps any one else, when you add your new environmental variables to Renviron, and you restart rstudio server, you may not initially see the extra environmental variables when you use system("env"). However, when you SWITCH projects at least once (after restarting rstudio server), you should see the new environmental variables you added when you call system("env")
  • akunyer
    akunyer almost 8 years
    This solution works for me using RStudio Server . Thanks !
  • Konrad Rudolph
    Konrad Rudolph over 4 years
    Unfortunately this sets the environment after R was started, not before, which means that environment variables that control application launch are disregarded. It appears that there is no workaround for the free version of RStudio Server, only for the Pro version.