RStudio Desktop V1.1.456 ignores R_LIBS_USER environmental variable


#1

I just upgraded RStudio for OSX to V1.1.456, and it does not recognize the R_LIBS_USER set in my .bash_profile. R from the console has no such problem. When I open RStudio, ignores my environment variable

R_LIBS_USER=/Users/bill/Library/R/3.4/library

so my libraries aren't available and the .rproj files fail. Rstudio seems to be making up its own R_LIBS_USER location, which doesn't exist:

> Sys.getenv("R_LIBS_USER")
[1] "~/Library/R/3.5/library"

If I switch to the Terminal, that has the correct value for R_LIBS_USER.

If I set .libPaths() manually and reload the packages it seems to work for that session, but fails again when I restart RStudio.

How do I fix this so RStudio respects the environment variable?


#2

Desktop applications in general will not read the values set in a startup shell profile (e.g. .bash_profile). You should instead set this variable within a file located at ~/.Renviron -- this ensures all R sessions (whether living in a shell or not) will get the requested library.

Also worth saying: RStudio appears to be setting the default library paths for R 3.5, while you want to use packages compiled for R 3.4. It's not advisable to use R packages compiled for a different version of R than the one currently in use.


#3

Thanks Kevin,
I'll change the ~/.Renviron immediately.

I used macOS package "updateR" from GitHub to move to R3.5.1, and it updates R_LIBS_USER in place. So I have 3.5 packages replacing the 3.4 packages in that directory.

EDIT:
After I restarted the same problem (libPaths() occurred. So RStudio on macOS does not appear to recognize R_LIBS_USER in .Renviron:

[~]$ cat .Renvrion 
R_LIBS_USER=/Users/bill/Library/R/3.4/library
[~]$ 

I ended up putting a .libPaths("/Users/bill/Library/R/3.4/library") call in .Rprofile