Skip to content
Prev 78252 / 398502 Next

Local install of a contributed package under Linux (was: R-code for binormla distribution)

On Sun, 2 Oct 2005, Jonathan Baron wrote:

            
But you still need to ensure that library() can find the packages.


I think the simplest way is that we have set up by default for new R 
users:

1) Set the environment variable R_LIBS.  For a site in 
R_HOME/etc/Renviron.site, or for a user in ~/.Renviron.  For example,
include the line

R_LIBS=~/R/library

2) Ensure that this directory exists, e.g.

mkdir -p ~/R/library

(If it does not exist the setting will be ignored, so it is safe to set it 
for all users.)

3) Use install.packages() inside R.  This will by default use the first 
element in .libPaths(), which will be ~/R/library.  Suggest to users that 
they use would do best to use

install.packages(pkgs, .libPaths()[1], dependencies = TRUE)

when they want to add packages, and update.packages(.libPaths()[1]) to 
update the packages they have installed.

Note that this works for Windows users too (although using ~ is perhaps 
dependent on setting HOME:  our Windows default use the network drive P: 
instead).