Working with R

R is available as a module (see Using Module for more information) and it is also an interactive app on Open onDemand (see Introduction to Open OnDemand (OOD) for more information). You can also use R with Anaconda. See Working with Conda/Miniconda/Anaconda and the Anaconda documentation for more information

If you work with R packages, using a Packrat environment can be helpful. Use the procedure below to create a Packrat environment on Discovery.

Creating a Packrat Environment (for R)

Packrat is an application that helps you manage packages for R. After you create a new directory for your R project, you can then use Packrat to store your package dependencies inside it. For more information about Packrat, see the website:

  1. Connect to Discovery.

  2. Type module load R/3.6.2.

  3. Create a new directory for your R project by typing, mkdir /scratch/<yourusername>/<directoryname> where yourusername is your user name, and directoryname is the name of the directory you want to create for your R project. For example, /scratch/j.smith/r_testlab

  4. Open the R interface and install Packrat:

    install.packages("packrat") #during the installation, you will be prompted to install in a local directory, as you cannot install as root
  5. Initialize the environment where R packages will be written to:


You can then install R packages that you need. For example, to install a package called rtracklayer, type the following:

if (!requireNamespace("BiocManager", quietly = TRUE))