Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rstudio different library path to command-line R (`$R_LIBS_USER`)

Tags:

r

rstudio

I'm trying to work out why my .libPath is different between command-line R and RStudio Desktop (NOTE: this is not a duplicate of this question as that fix involved stuff specific to RStudio Server which I don't have).

When I use R on the command-line (linux):

> .libPaths()
[1] "/home/mathematicalcoffee/R/library"  "/usr/local/lib/R/site-library"
[3] "/usr/lib/R/site-library"             "/usr/lib/R/library"           

When I use RStudio Desktop (linux, same machine):

[1] "/usr/local/lib/R/site-library" "/usr/lib/R/site-library"       "/usr/lib/R/library"            "/usr/lib/rstudio/R/library"  

Now I have set $R_LIBS_USER to ~/R/library in my bash profile, so R-command-line picks it up as my preferred libPath.

The problem is in RStudio Desktop when I do:

Sys.getenv('R_LIBS_USER')
# "~/R/x86_64-pc-linux-gnu-library/2.15"

So why has RStudio Desktop changed my R_LIBS_USER? How can I change it back? (I don't use an .Rprofile file). (In the question I linked above the solution for RStudio Server was to modify /etc/rstudio/rsession.conf, but I don't have that as I've got RStudio Desktop. Also, I believe RStudio should be respecting my R_LIBS_USER environment variable.)

like image 692
mathematical.coffee Avatar asked Apr 17 '13 00:04

mathematical.coffee


2 Answers

Just to document here in case someone finds it useful, according to ArchWiki we can define R_LIBS_USER in ~/.Renviron, which I feel is a more convenient way to define specific variables for R.

like image 68
GiovanniES Avatar answered Nov 15 '22 20:11

GiovanniES


You write:

Now I have set $R_LIBS_USER to ~/R/library in my bash profile,

Do you by chance call RStudio from a gui icon, ie without invoking your ~/.bash_profile ? Maybe you can try calling a wrapper instead which sets it?

For what it is worth, .libPaths() returns the same thing under RStudio Desktop and Server (though Server appends its internal directory), R on the command-line and via ESS for me.

Edit: And in general, do read help(Startup) which will be time well-spent. The comment by @flodel is quite appropriate. If you get lost dealing with this consistently at the system level, you can always turn to R, either at its system-level (via Renviron and Renviron.site) or via the ~/R/ directory.

like image 39
Dirk Eddelbuettel Avatar answered Nov 15 '22 20:11

Dirk Eddelbuettel