Creating a personal R package library on Enigma

NOTE: These instructions will apply to the Unix version of R installed on Enigma and Usher. They do NOT apply to the Windows version.

The installation of R on Enigma and Usher comes installed with all of the packages froom CRAN and Bioconductor. However, you may want to install a non-CRAN/Bioconductor package or perhaps an updated version of a package on CRAN/Bioconductor. In order to do this you need to create a personal R package library.

Most R installations are set to install contributed packages (i.e. from CRAN or Bioconductor) in system directories. Unfortunately, users do not have permission to write to this directory. Usually, only system administrators can write to this directory (and this is for good reason!). However, it is not necessary to install contributed packages in system directories. They can in fact be installed anywhere.

Note that you do not have to install packages separately on Enigma and Usher. Since they share the same filesystem and architecture, you only need to install the package on Enigma and it will be available to you on Usher (and the cluster).

Creating the package library

First, you need to create a directory in which packages will be installed. For example, in your home directory, you can create the directory Rlibs with the command
mkdir ~/Rlibs
Now you can install packages into this directory instead of the default system directory.

Installing a package in your personal package library

On Enigma (which is a Unix system), you need to install source packages. If you are ever given the choice of obtaining a source or a binary package, get the source package. Usually the name of the source package will be of the form
pkgName_x.y-z.tar.gz
where x.y-z is the version number for the package. Some packages may not have the z number. Once you've copied this file on to Enigma you can install it with the command
R CMD INSTALL -l ~/Rlibs pkgName_x.y-z.tar.gz
where, obviously, you should replace pkgName_x.y-z.tar.gz with the filename of the actual package you want to install. For example, if I wanted to install the tsModelSpec package, I would download the source package and save the file in my home directory on Enigma. Then issue the command (on Enigma)
R CMD INSTALL -l ~/Rlibs tsModelSpec_0.2.tar.gz

Getting R to recognize your personal package library

By default, R will not be aware of your personal package library and therefore will not be able to load any packages installed there. There are two ways to tell R about the location of your personal package library. Both ways are fine, but the .Renviron way is preferable.

The .Renviron Way

  1. In your home directory (cd ~ to get there) create a file called .Renviron using your favorite text editor.
  2. Enter the line
    R_LIBS=~/Rlibs
    in the .Renviron file.
  3. Save the .Renviron file in your home directory.
Now, startup R and run the command .libPaths() at the prompt. You should see the directory ~/Rlibs appear in the output. Now, are will be able to load packages from your personal package library.

In R, you can install packages from CRAN in your personal package library by using the lib argument to install.packages. For example,

install.packages("gpclib", "~/Rlibs")
installs the gpclib package in your personal package library.

Once you've created the .Renviron file you don't have to worry about it. Every time you start R, it will read the .Renviron file and register the location of your personal package library.

The R Way

There is another way to get R to recognize your personal package library:
  1. Startup R
  2. At the command prompt type .libPaths(). This will show you a list of directories where packages are installed. You'll see that there is only one directory, and it's the system directory.
  3. Now type .libPaths("~/Rlibs"). This tells R to add ~/Rlibs to the list of directories for R packages.

Unfortunately, you have to execute these steps every time you load up R because as soon as you quit, R forgets everything. The advantage of using the .Renviron method is that you only have to do it once.


Last modified 2008-07-29 by Roger D. Peng