Skip to end of metadata
Go to start of metadata

We encourage users to maintain their own R packages. This ensures that the user has no discontinuity in their workflow waiting for packages to be installed and that packages work with the user’s chosen, loaded R module. R packages are built specifically to a version of R and may not work properly if a different version of R is loaded. O2’s LMOD “module” feature allows users to quickly and easily switch between R versions.

Related commands:

Command Meaning
module avail R shows the versions of R installed on O2
module load R/version loads an individual module
module unload R/version unloads an individual module
which R shows the current version of R loaded
> installed.packages() from R, shows currently-installed packages

Setting up a personal R library

This sets up an environment to store R packages locally. From R, all packages will be installed and saved to this R library by default. It is recommended to use a separate R library for each version of R selected (swap Version Selected for the R chosen, like 3.2.5 or 3.3.3, etc). Multiple members of a group can share an R library saved in a group-accessible location by following the echo... and export... commands.

In O2 bash ($):

    mfk8@login02:~$ mkdir -p ~/R-VersionSelected/library
    mfk8@login02:~$ echo 'R_LIBS_USER="~/R-VersionSelected/library"' >  $HOME/.Renviron
    mfk8@login02:~$ export R_LIBS_USER="/home/user123/R-VersionSelected/library"

Starting R Interactively

R should not be executed from the login servers (login0X). Instead, launch an interactive session, specifying the memory requirements. R does not implicitly use multiple cores unless the code is parallelized, so 1 core is sufficient. Here’s a model R workflow:

	mfk8@login02:~$ srun --pty -p interactive -t 0-12:00 --mem 8000 -n 1 /bin/bash
	mfk8@compute-a-01-01:~$ module load gcc/6.2.0 R/3.2.5 #or version chosen
	mfk8@compute-a-01-01:~$ R
	> #notice how the prompt changes.

Installing Packages Using Bioconductor

The majority of bio-related packages can be downloaded through Bioconductor.

     > source("http://bioconductor.org/biocLite.R")
    > biocLite()
    > biocLite("nameofpackage")

 

User example:

     > source(http://bioconductor.org/biocLite.R")
    > biocLite("affy")
    > library(affy)

 

Bioconductor packages are listed at http://www.bioconductor.org/packages/release/BiocViews.html#___Software

Installing Packages Using CRAN

The command install.packages() searches CRAN by default and asks you to select a mirror, but a repos can be specified using this command:

     > install.packages("nameofpackage", repos="http://cran.r-project.org")

 

User example:

     > install.packages("foreign", repos="http://cran.r-project.org")
    > library(foreign)

 

A list of CRAN available packages is available at http://cran.r-project.org/web/packages/

Installing Packages from github using devtools

With the devtools package, users can install software from github repositories. First install and call library on devtools, then use the install_github() command.

	> install.packages('devtools')
	> library(devtools)
	> install_github('username/repo')

Installing Packages from Local File

If there is a package that needs to be manually downloaded (via wget/curl/etc), user should put the package in ~/R-VersionSelected/library and install it like this:

In R (>):

     > install.packages("name-of-your-package", lib="~/R-VersionSelected/library")

 

Conversely, if all dependencies are already existing for the package, R CMD INSTALL can be used from the command line (on an interactive compute node):

	mfk8@login02:~$ srun --pty -p interactive -t 0-12:00 --mem 8000 /bin/bash
	mfk8@compute-a-01-01:~$ module load gcc/6.2.0 R/3.2.5 #or version selected
	mfk8@compute-a-01-01:~$ R CMD INSTALL downloadedRPackage.tar.gz

Loading Packages

At the top of any script that uses an R package, the package must be explicitly called via library().

     > library("nameofpackage")

 

User case for a new R session, with these packages already installed:

     > library(affy)
    > library(foreign)

 
  • No labels