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

yang.rstudio's Avatar

yang.rstudio

21 Aug, 2011 06:52 AM

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?)

Slightly annoying in that I have to reinstall all packages 2x. Thanks in advance.

  1. Support Staff 2 Posted by Josh Paulson on 22 Aug, 2011 08:20 PM

    Josh Paulson's Avatar

    Hello,

    Thanks for posting this and will take a look and get back to you soon.

    Josh

  2. Support Staff 3 Posted by JJ Allaire on 22 Aug, 2011 09:48 PM

    JJ Allaire's Avatar

    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.

  3. 4 Posted by Donal MacCoon on 14 Aug, 2012 08:28 PM

    Donal MacCoon's Avatar

    I have tried to resolve this issue as suggested, but the file rsession.conf does not exist in /etc/rstudio/rsession.conf

    Using Sys.getenv(), I've confirmed that my library path, R_LIBS_USER, is "//habanero.keck.waisman.wisc.edu/home/maccoon/My Documents/R/win-library/2.13".

    I can write to this folder as confirmed by the creation of a "test" folder in the above folder. Yet, I cannot install an R package. When I try, I get the following error:

    Installing package(s) into ‘C:/Program Files (x86)/R/R-2.13.1/library’
    (as ‘lib’ is unspecified) Warning in install.packages :
    'lib = "C:/Program Files (x86)/R/R-2.13.1/library"' is not writable Error in install.packages : unable to install packages

    This suggests to me that despite what R_LIBS_USER says, RStudio is still trying to install packages to the default program directory. It fails b/c I do not have write access to that directory.

    Any suggestions?

    Thank you.

  4. Support Staff 5 Posted by Josh Paulson on 15 Aug, 2012 08:19 PM

    Josh Paulson's Avatar

    Donal,

    The rsession.conf file does not exist by default and you need to create it. Here is the documentation for configuring the server and it indicates what directory you should put it in:

    http://www.rstudio.org/docs/server/configuration

    Josh

  5. 6 Posted by dgmaccoon on 17 Aug, 2012 08:09 PM

    dgmaccoon's Avatar

    This comment was split into a new discussion: R .libPaths() difference between RStudio and command-line R

    Thank you for your help Josh.

    These appear to be instructions for *nix machines. I'm needing to have the
    equivalent information for a windows computer.

    Thank you,

    Donal

  6. Josh Paulson closed this discussion on 18 Aug, 2012 04:20 PM.

Comments are currently closed for this discussion. You can start a new one.