Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R .libPaths() difference between RStudio and command-line R

Tags:

r

rstudio

When I run R from the command line:

> library(ggplot2)
...
> path.package('ggplot2')
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13/ggplot2"
> .libPaths()
[1] "/home/yang/R/x86_64-pc-linux-gnu-library/2.13"
[2] "/usr/local/lib/R/site-library"                
[3] "/usr/lib/R/site-library"                      
[4] "/usr/lib/R/library"                           
> Sys.getenv('R_LIBS_USER')
[1] "~/R/x86_64-pc-linux-gnu-library/2.13"

(Note: that environment variable actually doesn't exist when I check from my shell.)

But from RStudio Server running on the same box, and after logging in as the same user:

> path.package('ggplot2')
[1] "/home/yang/R/library/ggplot2"
> .libPaths()
[1] "/home/yang/R/library"              "/usr/local/lib/R/site-library"    
[3] "/usr/lib/R/site-library"           "/usr/lib/R/library"               
[5] "/usr/lib/rstudio-server/R/library"
> Sys.getenv('R_LIBS_USER')
[1] "/home/yang/R/library"

Can you explain why these are different by default? Is this an RStudio customization? (Why?) Thanks in advance.

like image 748
Yang Avatar asked Aug 20 '11 02:08

Yang


Video Answer


2 Answers

Direct answer from the source:

http://support.rstudio.org/help/discussions/questions/204-r-libpaths-difference-between-rstudio-and-command-line-r

Hi there,

Yes, we have a custom R_LIBS_USER setting which is intended to make it easier to upgrade the server to a new version of R without requiring that every user rename their library directory and/or re-build their packages. That way the administrator can do an upgrade without fearing that they'll break their user's working environment (realize that this could also be accomplished by writing an upgrade script that does the requisite rename/rebuild for each user).

Fully agree that this isn't necessarily desirable in all cases. Here is what you can do to work around it:

The Rtudio Server R_LIBS_USER is controlled by the following setting in /etc/rstudio/rsession.conf:

r-libs-user=~/R/library

This variable supports the same wildcarding as R_LIBS_USER (as described here: http://stat.ethz.ch/R-manual/R-patched/library/base/html/libPaths.html) so you could change this to the following to make RStudio behave just like console R:

r-libs-user=~/R/%p-library/%v

(note I believe that is the right syntax to reproduce the directory shown in your output above but you'll definitely want to double check that)

Hope that clears things up and that you can get things configured as you'd like. Let us know if you have other questions or if this doesn't work as described.

J.J.

like image 167
Yang Avatar answered Sep 25 '22 15:09

Yang


A quick googling got me here:

http://support.rstudio.org/help/discussions/problems/868-how-to-configure-libpaths

so it looks like RStudio uses its own libs, set in /etc/rstudio/rsession.conf. Why? Who knows.

like image 39
Spacedman Avatar answered Sep 26 '22 15:09

Spacedman