Below are some instructions for installing an R package into your own disk space (so that you don't need to ask the busy systems manager).
To install a package (in Unix) which is not part of the main distribution of R, follow the steps below.
- go to http://www.r-project.org or a local mirror site http://cran.stat.sfu.ca and get the source as a gzipped tar file, an example is the package sspir_0.2.3.tar.gz for State Space Models in R
extract from the tar file with (say under your ~/tmp directory)
mkdir ~/tmp # if directory doesn't already exist mv ~/sspir_0.2.3.tar.gz ~/tmp cd ~/tmp tar xzvf sspir_0.2.3.tar.gz
compile the source (typically C and/or fortran routines) and install into your local directory (say ~/Rlib) with the following Unix command line (where you replace $HOME with your home directory which is the output of 'echo $HOME').
R CMD INSTALL --library=$HOME/Rlib sspir
To use the package, you need the lib.loc option for library()
> library(sspir,lib.loc="$HOME/Rlib") > library(help=sspir,lib.loc="$HOME/Rlib")
With newer versions of R, the above can be combined into one step
R CMD INSTALL --library=$HOME/Rlib sspir_0.2.3.tar.gz
If you decide later you don't want the package, then from the Unix command line
R CMD REMOVE --library=$HOME/Rlib sspir
If you want to let others use your locally added packages, just set permissions appropriately to $HOME/Rlib, e.g.
chmod -R og+rX $HOME/Rlib
- Note that the different flavors of Unix on our network. A package compiled in one computer (e.g. 32-bit Linux) should work on another computer with the same architecture. If you work on different servers on our network, then you would have to compile separate versions. In this case, one possibility is something like subdirectory Rlib_linux32, Rlib_linux64, Rlib_solaris64 under your $HOME
Alternatively, after testing the package, you can ask the systems manager to install it (be clear whether you want the Solaris or Linux version) by providing the following instructions (where you replace $MYRPKGTARDIR with the directory where the tar file is unpacked, and replace $PKG with the name of the package)
cd $MYRPKGTARDIR R CMD INSTALL $PKG
As a final note, if you want to install a package in Windows, the simplest thing to do is:
- go to http://www.r-project.org/ and get the zip file with the Windows compiled version
- unzip the file under $RHOME/library, where $RHOME is the folder where you installed R
- if you don't have write access to $RHOME, just unzip the package anywhere and use library() with lib.loc argument to load the package later
- Alternatively, use the installer in the R console menu.