R
R is a popular environment for data analysis, statistics and machine learning. Most frequently RStudio is used as the IDE (integrated development environment) of choice by R users.
Overview
We support multiple versions of R/Studio on ReD services:
- 4.5.x, RES and ParallelCluster
- 4.4.x, RES and ParallelCluster
- 4.3.x, ParallelCluster only
- 4.2.x, ParallelCluster only
We may update revisions (x in 4.5.x) as needed for vulnerability management, but this should not affect runtime execution.
R/RStudio in RES
Both R 4.5.x and 4.4.x are installed directly in the RES images and are available from the Start/Applications menu and as shortcuts on the Desktop. The same goes for RStudio. When first starting RStudio, you'll be asked to choose which R version you wish to work with. One can change versions via the menu Tools > Global Options. In the Options window, select General in the left pane and the Basic tab. Finally, select the Change... button in the top R version section.
R/RStudio in ParallelCluster
R/RStudio, like the other Open Ondemand GUI applications, is deployed centrally as a containerized application, one container for each version, and the most recent versions are stored in our singularity directory at /shared/software/singularity/current_continers/:
[jharvard@ip-1.1.1.1 singularity]$ ls -al current_containers
...
lrwxrwxrwx. 1 root root 84 Oct 6 19:02 urcds-rstudio_4.2.3.sif -> /shared/software/singularity/100625/urcds-rstudio_4.2.3_2025-10-06_2025.09.1-401.sif
lrwxrwxrwx. 1 root root 84 Oct 6 19:00 urcds-rstudio_4.3.3.sif -> /shared/software/singularity/100625/urcds-rstudio_4.3.3_2025-10-06_2025.09.1-401.sif
lrwxrwxrwx. 1 root root 84 Oct 6 18:51 urcds-rstudio_4.4.3.sif -> /shared/software/singularity/100625/urcds-rstudio_4.4.3_2025-10-06_2025.09.1-401.sif
lrwxrwxrwx. 1 root root 84 Oct 6 18:48 urcds-rstudio_4.5.1.sif -> /shared/software/singularity/100625/urcds-rstudio_4.5.1_2025-10-05_2025.09.1-401.sif
urcds-rstudio_X.Y.Z.sif where X=major, Y=minor, and Z=revision version numbers. R/RStudio GUI Interactive Jobs
For interactive GUI use in Open OnDemand, the logistics of executing R/RStudio within the container is handled for you – no extra effort required. Please see our Running Open OnDemand Interactive Applications documentation.
R/RStudio Interactive Command-Line and Batch Jobs
Running R/RStudio from the command-line, whether interactively or in batch, takes a bit more effort. This involves pointing to the container, prepping your bind mounts, noting any additional options needed for the runtime environment in the container (e.g. enabling GPU support), and then calling the appropriate entrypoint either in your script or interactively on the command line. See our Running Jobs docs for examples of these two job submission patterns.
The following code file and job submssion command illustrates hjow to run R code via a batch job:
#
# file R_test_script.sh containing our job
#
# Note this example uses a bash heredoc: when executed, it creates the SLURM job file
# and then submits it. See https://en.wikipedia.org/wiki/Here_document
# Create our slurm job script...
cat << EOF > R_test_script.slurm
#!/bin/bash
#SBATCH --job-name=R_test # Job name
#SBATCH --output=%x_%j.out # Output file (%x expands to Job name, %j expands to job ID)
#SBATCH --error=%x_%j.err # Error file
#SBATCH --ntasks=1 # Number of tasks (processes)
#SBATCH --nodes=1 # Run on only 1 node
#SBATCH --cpus-per-task=1 # Number of CPU cores per task
#SBATCH --mem=4G # Total memory per node
#SBATCH --time=00:30:00 # Time limit (hh:mm:ss)
#SBATCH --partition=urcdtest-med # Partition name
#SBATCH --open-mode=append # Ensure that log files are appended (vs truncate) on job restarts
# Set up 'global' variables
LAB_DIR=/data/labs/harvardj_lab
PROJ_DIR=$LAB_DIR/projects/my_project
# Set up container details
# Binds are needed to tie outside directories to locations inside. We are using shorthand format
# since inside and outside are the same (format: outside/[:inside/]). Omit
# last part if not part of NSAPH FASSE.
# Omit GPU option if not needed
#
export R_VERSION=4.5.2
export R_LIBS_USER=$HOME/R/R_${R_VERSION}
container_rstudio=/shared/software/singularity/current_containers/urcds-rstudio_${R_VERSION}.sif
binds="-B /shared,/data,/nsaph-fasse"
gpu_support="--nv"
# Now run our code inside the container
# Entry point can be 'exec', 'run', ...
singularity exec \
$binds $gpu_support \
${container_rstudio} \
Rscript my_code.R
# now report our job efficiency when exiting
seff $SLURM_JOBID
EOF
# And now submit the job...
sbatch R_test_script.slurm
Note: R_LIBS_USER problem
R_LIBS_USER is not being set correctly in the software container for command line interactive and batch jobs. Include in your ~/.bash_profile the line export R_LIBS_USER=$HOME/R/R_# where # is your R version number. Otherwise, include it per-script as in the abvoe example if you use multiple R versions.
R Packages & Considerations
A number of packages beyond the core/base R have been installed in ReD's services. If additional packages are needed, one can leverage the Posit Package Manager (PPM) to install them: if packages are free of vulnerabilities (as reported by the Open Source Vulnerabilities reports), PPM will pull the code from CRAN realtime for your session to install.
Please see our Posit Package Manager documentation for details on how to configure R/RStudio appropriately.
INLA
This package is available for R ≥ v4.5 only.
TL;DR: The default installation of the most recent INLA versons (v2025-12-x) had problems at runtime as the execute permissions had not been set on some of the run scripts (*.run). This problem has been corrected in R/RStudio v4.5.x.
After correcting this problem, we discovered that the OS/system libraries required for this version of the title were too new for our environment, and the program would crash with GLIBC errors. We were able to fix this by downgrading to an earlier version – INLA_24.09.14 built 2024-09-14. However, INLA would not install on versions of R/RStudio prior to v4.5.x, as several of the dependencies do not exist in CRAN.
Unfortunately, the software developers will not fix this problem; their stated remedy is to upgrade to R >= 4.5.
reticulate
(more soon)
sf on PC/OOD
sf is a package that provides simple features access for R. As it interfaces with GDAL, PROJ, and GEOS, which have complex code bases, sf itself can be tricky to install. For that reason, we provide (or try to) preinstalled versions of sf with our R/RStudio installations in PC/OOD. Forage ahead if you need to (re)install...
Symptoms
You'll need to install sf manually, and via source, if it is not already installed, or if one observes the following:
> library(sf)
Error: package or namespace load failed for 'sf' in dyn.load(file, DLLpath = DLLpath, ...): unable to load shared object '/shared/home/jharvard/R/R_4.5.1/sf/libs/sf.so': libproj.so.22: cannot open shared object file: No such file or directory
With the PPM repo URL configured as your CRAN location, the following command still does not work as expected:
Troubleshooting, one uncovers the following, layered problems:
PROJand its libraries are installed, but the links fromsfappear to be broken.- 64-bit libraries are usually stored in
/lib64/, not/lib/. - RStudio or PPM appears to be ignoring the "source" parameter for installation.
- When one tries to install the source, the
gdal-configprogram appears to be missing.
Resolution
Remedying this problem requires work both outside of and inside RStudio.
Outside RStudio - Setup the gdal-config Workaround
- On Open OnDemand, from the Dashboard menu select Clusters > "_ urcds-red-pc-prod Shell Access"
- In the terminal window that appears, enter the following commands:
This step is necessary to help the source installer for sf find the gdal-config program, which is installed but is named something other than expected.
Inside RStudio - Adjust PPM configuration
To force RStudio pull the source code for installing sf, we'll change the PPM repo URL to point to the source packages.
- Start an interatcive Rstudio sessions from the OOD Dashboard > Interactive Apps menu. Choose your preferred RStdio version.
- In the Console pane, issue the following command:
# source install for CRAN
Sys.setenv(R_LIBCURL_SSL_REVOKE_BEST_EFFORT=TRUE)
options(repos = c(CRAN = "https://mirrors.sanitization.red.rc.harvard.edu/cran/latest",
pRSPM="https://mirrors.sanitization.red.rc.harvard.edu/bioconductor-3.21/latest"))
Inside RStudio - Reinstall sf
-
If you've installed 'sf' yourself via
install.packages()or some other method, remove what you've installed via issuing the commandremove.packages('sf')in the Console pane. -
To include the
gdal-configworkaround, update the executionPATHfor RStudio's session with the following command:
Sys.setenv("PATH" = "/opt/R/4.5.1/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/rstudio-server/bin:/usr/lib/rstudio-server/bin/quarto/bin:/usr/lib/rstudio-server/bin/postback:~/.local/bin:/shared/home/yourusername/.local/bin")
Note: (a) The command is long and may wrap across multiple lines – it should be a single line. (b) You'll need to fill in your username towards the end of the command.
- Install the package
sffrom the source code with optional arguments:
install.packages("sf", type = "source", configure.args = "--with-proj-lib=/lib64/", verbose = TRUE)
[...snip...]
** checking absolute paths in shared objects and dynamic libraries
** testing if installed package can be loaded from final location
** testing if installed package keeps a record of temporary installation path
* DONE (sf)
The downloaded source packages are in
'/tmp/RtmpS0UEZa/downloaded_packages'
At this point you should be able to load the library without error:
Inside RStudio - Reset PPM Configuration to Default
To reset RStudio to pull binary packages once again, issue the appropriate R repo URL command listed for PPM in the Console. At last update, it is:
# binary install for CRAN
Sys.setenv(R_LIBCURL_SSL_REVOKE_BEST_EFFORT=TRUE)
options(repos = c(CRAN="https://mirrors.sanitization.red.rc.harvard.edu/cran/__linux__/rhel9/latest",
pRSPM="https://mirrors.sanitization.red.rc.harvard.edu/bioconductor-3.21/latest"))
You can skip this step if you have this command in your .Rprofile, as the repo URL will be reset when next starting Rstudio.
Last Updated: Oct 15, 2025