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" 开发者_StackOverflow社区
[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.
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.
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.
精彩评论