E-mail Tips and Installing R Packages Locally
Wednesday, May 24th, 2006, 2:00 P.M.
E-mail Tips
Installing R Packages Locally
If you want to install your own R packages but you don't have superuser access to the computer you're working on (such as your workstation or statcomp), you can have R install them into your home directory (or any other directory you have write access to).
First create a directory where you want R to install packages, such as
.R-library
.
Next, you need to edit your
~/.bashrc
file so that it sets the
R_LIBS
environment variable. This variable is what tells R where you want packages installed. Add the following line to the end of
~/.bashrc
:
export R_LIBS=~/.R-library
Whenever you edit your
.bashrc
file, you need to either close and re-open your console or re-source
.bashrc
by running
source ~/.bashrc
in order for the changes to apply. You only need to do this whenever you make changes; every time after that your console will be set up correctly. Go ahead and reload your settings now.
Now that you've got your
R_LIBS
environment variable set, R will always install packages into the
.R-library
directory, which lives in your home directory. You can test this by looking at the return value of the
.libPaths function in R. If the
.R-library directory is in the character vector returned by
.libPaths()
, then you've successfully set up R to install packages locally! This works with both the
install.packages()
function and by running
R CMD INSTALL
.
For more information about installing add on packages, check out the
Add-on packages section of the
R Installation and Administration Manual.