Installing R packages

Mon 22 March 2010 — Filed under notes; tags: R-language

Notes to myself about installing R packages.

Installing from CRAN

install.packages(c("ape","sqldf","ROCR"), repos="http://cran.fhcrc.org/", dependencies=TRUE, clean=TRUE)

Bioconductor

source("http://bioconductor.org/biocLite.R")
biocLite(c("Biostrings","BSgenome")) # for example

Update all of bioconductor

source("http://bioconductor.org/biocLite.R")
update.packages(rep=biocinstallRepos(), ask=FALSE)

Check out and install a package (eg, Biostrings) from the Subversion repository. See http://wiki.fhcrc.org/bioc/SvnHowTo

svn checkout --username=readonly --password=readonly https://hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/Biostrings
R CMD INSTALL Biostrings

R-forge

install.packages("packagename",repos="http://R-Forge.R-project.org")

Read-only subversion repository may be checked out using

svn checkout svn://svn.r-forge.r-project.org/svnroot/packagename

Installing packages locally

If you can't (or don't want to) install packages to the system R location, you can create a local library. For example:

echo 'R_LIBS_USER="~/R/library"' >  $HOME/.Renviron
mkdir -p ~/R/library
R CMD INSTALL --library=~/R/library somepackage.gz

Reloading a package

Calling library() after a package has already been loaded does not update the namespace with updates if the library has changed (eg, during package development). Instead, do something like this:

relibrary <- function(pkg){
    unloadNamespace(pkg)
    library(pkg, character.only=TRUE)
}