Skip to content

R#

R is a language and environment for statistical computing and graphics. The cluster has multiple versions installed with a variety of commonly used packages pre-installed.

Package Installation#

R uses a central package library that contains many common packages. The location of this library is $R_HOME/library. Users may also install their own packages locally. The default location for local package installation is $HOME/R/x86_64-pc-linux-gnu-library/4.4.

Check installed package list first!

Your package installation command will not check the centrally installed packages. You should always check if your package is already installed before proceeding. RCC provides an up-to-date list of installed R packages for the most recent version.

User Package Install#

First load the R module:

module load R

Launch R:

R

Run the install command:

> install.packages('SomePkg')

The first attempt will warn about writing to the central library. It will ask you to create and use a personal library. Answer yes to both.

Installing package into /hpc/apps/R/4.4.0/lib64/R/library(as lib is unspecified)
Warning in install.packages("ggplot2") :
  'lib = "/hpc/apps/R/4.4.0/lib64/R/library"' is not writable
Would you like to use a personal library instead? (yes/No/cancel) yes
Would you like to create a personal library~/R/x86_64-pc-linux-gnu-library/4.4to install packages into? (yes/No/cancel) yes

Your package will be installed to your home directory. This package can be removed or updated using the standard R commands.

Did you check the installed package list first?

Your package installation command will not check the centrally installed packages. You should always check if your package is already installed before proceeding. RCC provides an up-to-date list of installed R packages for the most recent version.

Request Package Install#

Some packages require system libraries and/or advanced dependencies in order to install correctly. If you see errors when you're installing a package, send a package install request to help-rcc@mcw.edu and RCC will update the central library.

Running R Jobs#

R can be run in batch or interactive jobs. Please do not run long or resource intensive R scripts on the login node.

Small Interactive Jobs#

Small interactive jobs include light plotting, simple analysis of small data sets, etc. These jobs never take more than one core, a few GB of memory, and never last more than a few minutes. These small, fast jobs are allowed on a login node. However, use caution when running these jobs and double-check that they will not use larger resources. If you need to run an interactive R workflow that is more resource intensive, please use an interactive cluster job.

To get an interactive session to run R on the cluster:

srun --ntasks=1 --mem-per-cpu=4GB --time=01:00:00 --job-name=interactive --pty bash

Multi-core Jobs#

Multi-core jobs should be run on the cluster compute nodes using the Torque queuing system. There are several options for running these jobs in Torque, including the Rscript command and the BatchJobs library. Both methods interface R with Torque, however, their use cases are different. The Rscript command should be used when you have written an R program .r file and would like to run this script on the cluster. The BatchJobs library should be used when you would like to test individual functions in a semi-interactive way and submit this work to the cluster.

Example SLURM submission script:

#!/bin/bash
#SBATCH --job-name=R-test
#SBATCH --ntasks=1
#SBATCH --mem-per-cpu=1gb
#SBATCH --time=00:01:00
#SBATCH --output=%x-%j.out

module load R/4.4.0

Rscript Rtest.r  

Submit the job:

sbatch myRtest.sh

Help#

If you have questions about running R on the HPC cluster, please contact help-rcc@mcw.edu for assistance.