Skip to content

R (Programming Language)

Important Security Notice: R Version < 4.4.0

A critical security vulnerability (CVE-2024-27322) has been identified in R versions prior to 4.4.0, which poses a risk of allowing malicious arbitrary code execution through deserialization of untrusted data. It is recommended to use at least version v4.4.0, which includes crucial security patches.

Learn More »

Overview

R (more info) is a popular programming language used for statistical computing and visualizing data. We've seen its use increase in projects relating to data science and bioinformatics.

Looking for RStudio?

Instead of using the command line for running R commands, you also can use our online version of RStudio Server, which is similar to what you might run on your desktop.

R 4.6.0 and above are set up to be parity with the same version in RStudio, where packages installed in one are usable in the other.

Learn More »

Availability

Cluster Module/Version
BOSE R/4.0.4
R/4.0.5
R/4.2.1
R/4.3.1
R/4.4.0
R/4.6.0
BGSC R/3.4.4
R/3.6.3
R/4.0.2
R/4.4.0

Note: While you can simply use module load R to activate the most recently installed version of this software, it's highly recommended to choose a specific version as packages are installed on a per-version basis and an updated release could happen at any time.

Installing Packages

As of R/4.6.0, packages can be installed either directly through R, or within RStudio in Open OnDemand. Previous versions require installing packages individually.

Start R
module load R/4.6.0
R
Run R Commands (in R)
> install.packages("zoo")

Package files are stored in ~/.local/R-Packages/{{VERSION}}, however modules before 4.6.0 are not broken up by version and may cause some inconsistency.

Changing Your R Version

If you decide to use a different version of R, such as a newer one, you may need to install all of your packages again.

Starting in R 4.6.0 packages are tied directly to the version of module that you load.

Interactive Mode vs Script Files

R is primarily used in two ways: interactively (manually typing each command) and through running scripts (running all commands together).

Interactive Mode

If you want to run R commands manually and see each of their results in real time, you'd use the R command directly, then type each command you want to run.

Start R
sinteract           # Start an interactive session on the cluster
module load R/4.6.0       # Load the R module
R                   # Start the R program
Run R Commands (in R)
> 1+1
[1] 2

> text <- "Hello"
> paste(text, "World")
[1] "Hello World"

> q()
Quit Interactive Mode
exit

Scripts Mode

Rather than typing each R command individually, you can use the Rscript command to run a list of multiple R commands in a file. This is especially useful when using sbatch in Slurm to submit your work to a compute node for long-running calculations.

my-script.R
1+1

text <- "Hello"
paste(text, "World")
Run Script
sinteract       # Start an interactive session on the cluster (if not using 'sbatch')
module load R/4.6.0   # Load the R module
Rscript my-script.R     # Run R script
Output
[1] 2
[1] "Hello World"
Quit Interactive Mode
exit           # If you used 'sinteract' above

Sample Slurm Script

submit.sh
#!/bin/bash
# -- SLURM SETTINGS -- #
# [..] other settings here [..]

# The following settings are for the overall request to Slurm
#SBATCH --ntasks-per-node=32     # How many CPU cores do you want to request
#SBATCH --nodes=1                # How many nodes do you want to request

# -- SCRIPT COMMANDS -- #

# Load the needed modules
module load R/4.6.0   # Load R
Rscript my-script.R
Submit Job
sbatch submit.sh

Real Example

Has your research group used R in a project? Contact the HPC Team and we'd be glad to feature your work.

Resources