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.
||shows the versions of R installed on O2|
||loads an individual module|
||unloads an individual module|
||shows the current version of R loaded|
||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
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="~/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 8G -c 1 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, example installation given below. Please reference the installation page on the Bioconductor website in case this method changes in the future.
Bioconductor packages are listed at http://www.bioconductor.org/packages/release/BiocViews.html#___Software
Installing Packages Using CRAN
install.packages() searches CRAN by default and asks you to select a mirror, but a repos can be specified using this command:
A list of CRAN available packages is available at http://cran.r-project.org/web/packages/
Installing Packages from github using devtools
devtools package, users can install software from github repositories. First install and call library on devtools, then use the
> 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 (>):
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
Installing Other R packages
For installing other packages (e.g., sf or monocle3), please visit our O2 wiki page.
At the top of any script that uses an R package, the package must be explicitly called via
User case for a new R session, with these packages already installed: