Before I upgrade to R-2.14, I want to take the opportunity to rationalise the folder structure of my installed packages.
At the moment I use the R default, i.e. all new installed packages goes to R_LIBS_USER. However, I really distinguish between two classes of package:
plyr
, data.table
, etc.Since install.packages
offers one the option to specify a lib
argument, this is clearly possible.
Is there an easy way to manage package locations, e.g. by creating some sensible settings / wrapper function in .RProfile
or RProfile.Site
?
To set environment variable R_LIBS_USER in Windows, go to the Control Panel (System Properties -> Advanced system properties -> Environment Variables -> User Variables) to a desired value (the path to your library folder), e.g.
R uses a single package library for each installed version of R on your machine. Fortunately it is easy to modify the path where R installs your packages. To do this, you simply call the function . libPaths() and specify the library location.
R packages are installed in a directory called library. The R function . libPaths() can be used to get the path to the library.
There are numerous options for that. The first thing I did was adapt my Rprofile.site to contain the following line, making my default library path a directory not included in my R installation.
.libPaths(c("D:/R/Library",.libPaths()))
This makes D:/R/Library
my default path without losing the other paths. You can add two paths to that one, say D:/R/Library/Work
and D:/R/Library/Test
. The one that's put in the first position is the default one used if you don't specify lib in install.packages()
.
Then you can assign two variables in your .Rprofile.site. These ones are assigned in the base namespace, and hence always accessible and not removed by ls(). Something like
.libwork <- 'D:/R/Library/Work' .libtest <- 'D:/R/Library/Test'
which allows you to install packages like:
install.packages('aPackage',lib=.libwork)
There are other options too I guess, but this is how I would roll.
Hadley's excellent package devtools
provides a function dev_mode
.
http://www.inside-r.org/packages/cran/devtools/docs/dev_mode
Here you can find an example usage: https://gist.github.com/1150934
Basically,
dev_mode(TRUE, path = "anywhere-you-want-to-install") install.packages("anything-that-you-want-to-install")
is a powerful way.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With