Installing R Libraries

While the BCG installs a very large number of R packages by default, from both CRAN and Bioconductor, sometimes people will want to install packages for themselves.

The Default

Just use the R command install.packages('PACKAGE_NAME'). R will tell you that it cannot write to the central library directory, and ask you if you want to install a private version. Say 'yes,' and also accept the location. It will install the library for you and you're done.

Note: when a new version of R is installed, you may need to reinstall your privately built packages. Not always, but sometimes the version changes will break the private libraries.

With More Control

You can set an environment variable which will let you decide where your personal libraries go. This might be useful if, for example, you needed to compare multiple versions of the same library. By changing the environment variable, you could install and load the different versions.

  export R_LIBS=~/R_libs   # or wherever you want it to go
  mkdir ~/R_libs

You will want to set the R_LIBS variable in your ~/.profile file, so that it is set in every new shell you start. Alternatively, you can create the file ~/.Renviron, with this line:

  R_LIBS="~/R_libs"

Note: if you use multiple operating systems (OS X and Linux, say), you'll need to make sure that your R_LIBS variable is different on the different operating systems. If you're unused to configuring your shell environment for multi-platform use, send an email to sysreq@biostat.wisc.edu with an explanation of what you're trying to do, and will help you set that up.