A guide for installing R packages using the software modules available on CARC HPC clusters.
The following instructions are based on the R 4.3.2 module:
module purge
module load gcc/11.3.0
module load openblas/0.3.20
module load r/4.3.2
They should work for any R version based on gcc/11.3.0
and openblas/0.3.20
. Older R versions or older versions of R packages may require different steps.
Some packages require creating/modifying the file ~/.R/Makevars. Create a blank file with the following commands in the shell:
mkdir ~/.R
touch ~/.R/Makevars
Installing R packages from source
On Linux, R packages are installed from source by default. For some R packages, certain modules need to be loaded to install the package (build dependencies) and the same modules may also need to be loaded in order to load and use the R package (run dependencies). Packages that require specific steps to install on CARC HPC clusters are detailed below.
If using the RStudio Server app via CARC OnDemand, use the terminal tab within RStudio to install the packages listed below on the command line. Load the required modules in the shell, then enter R
to open an R session and install packages. In some cases you may need to load additional modules in future RStudio Server sessions via the “Additional modules to load” option on the app form in order to use the packages.
tidyverse
In the shell:
module load pkgconf libpng libjpeg-turbo libtiff zlib bzip2 libxml2 curl fontconfig freetype graphite2 pcre harfbuzz fribidi glib openssl icu4c
In R:
install.packages("tidyverse")
devtools
In the shell:
module load pkgconf libpng libjpeg-turbo libtiff zlib bzip2 libxml2 curl fontconfig freetype graphite2 pcre harfbuzz fribidi glib openssl icu4c automake autoconf libtool m4
In R:
install.packages("devtools")
XML
In the shell:
module load pkgconf libxml2 xz libiconv
In R:
install.packages("XML")
xml2
In the shell:
module load libxml2
In R:
install.packages("xml2")
openssl
In the shell:
module load openssl
In R:
install.packages("openssl")
curl
In the shell:
module load curl
In R:
install.packages("curl")
RCurl
In the shell:
module load curl libxml2
In R:
install.packages("RCurl")
systemfonts
In the shell:
module load pkgconf libpng zlib libxml2 fontconfig freetype
In R:
install.packages("systemfonts")
textshaping
In the shell:
module load pkgconf libpng zlib libxml2 fontconfig freetype graphite2 pcre harfbuzz fribidi glib
In R:
install.packages("textshaping")
ragg
In the shell:
module load pkgconf libpng libjpeg-turbo libtiff zlib bzip2 libxml2 fontconfig freetype graphite2 pcre harfbuzz fribidi glib
In R:
install.packages("ragg")
stringi
In the shell:
module load icu4c
In R:
install.packages("stringi")
igraph
In the shell:
module load libxml2
In R:
install.packages("igraph")
httpuv
In the shell:
module load zlib automake autoconf libtool m4
In R:
install.packages("httpuv")
haven
In the shell:
module load pkgconf zlib
In R:
install.packages("haven")
git2r
In the shell:
module load git libgit2 openssl zlib
In R:
install.packages("git2r")
When using the package, make sure to module load git libgit2
first.
Cairo
In the shell:
module load pkgconf libpng libjpeg-turbo libtiff zlib bzip2 libxml2 icu4c cairo pcre fontconfig freetype graphite2 pcre harfbuzz fribidi glib libx11 libxau libxt libxext libxcb libxdmcp libxrender xproto xextproto kbproto renderproto libffi pixman
In R:
install.packages("Cairo", repo = "https://rforge.net")
png
In the shell:
module load zlib libpng
In R:
install.packages("png")
jpeg
In the shell:
module load libjpeg
export JPEG_CFLAGS=-I$LIBJPEG_ROOT/include
export JPEG_LIBS=-L$LIBJPEG_ROOT/lib
In R:
install.packages("jpeg")
When using the package, make sure to module load libjpeg
first.
rsvg
In the shell:
module load pkgconf librsvg libpng glib gobject-introspection util-linux shared-mime-info cairo gdk-pixbuf pcre pixman fontconfig freetype zlib libxml2 libffi libx11 libxrender libxext libxcb libxau libxdmcp xproto renderproto kbproto xextproto
In R:
install.packages("rsvg")
When using the package, make sure to module load librsvg
first.
ggiraph
Create/modify ~/.R/Makevars to include:
CPPFLAGS = -I${ZLIB_ROOT}/include -I${LIBPNG_ROOT}/include
LDFLAGS = -L${ZLIB_ROOT}/lib -L${LIBPNG_ROOT}/lib
In the shell:
module load zlib libpng
In R:
install.packages("ggiraph")
ncdf4
In the shell:
module load openmpi/4.1.4 netcdf-c
In R:
install.packages("ncdf4")
hdf5r
In the shell:
module load openmpi/4.1.4 hdf5 zlib
In R:
install.packages("hdf5r")
When using the package, make sure to module load openmpi/4.1.4 hdf5
first.
bigmemory
Create/modify ~/.R/Makevars to include:
CPPFLAGS = -I${LIBUUID_ROOT}/include
LDFLAGS = -L${LIBUUID_ROOT}/lib
In the shell:
module load libuuid
In R:
install.packages("bigmemory")
units
In the shell:
module load openmpi/4.1.4 sqlite geos gdal proj udunits
In R:
install.packages("units", configure.args = "--with-udunits2-lib=${UDUNITS_ROOT}/lib --with-udunits2-include=${UDUNITS_ROOT}/include")
udunits2
In the shell:
module load openmpi/4.1.4 sqlite geos gdal proj udunits
In R:
install.packages("udunits2", configure.args = "--with-udunits2-lib=${UDUNITS_ROOT}/lib --with-udunits2-include=${UDUNITS_ROOT}/include")
rgdal
In the shell:
module load openmpi/4.1.4 sqlite geos gdal proj udunits
In R:
install.packages("rgdal")
When using the package, make sure to module load openmpi/4.1.4 sqlite geos gdal proj udunits
first.
s2
In the shell:
module load openssl
In R:
install.packages("s2")
sf
In the shell:
module load openmpi/4.1.4 sqlite geos gdal proj udunits
In R:
install.packages("sf", configure.args = "--with-sqlite3-lib=${SQLITE_ROOT}/lib")
When using the package, make sure to module load openmpi/4.1.4 sqlite geos gdal proj udunits
first.
terra
In the shell:
module load openmpi/4.1.4 sqlite geos gdal proj udunits
In R:
install.packages("terra", configure.args = "--with-sqlite3-lib=${SQLITE_ROOT}/lib")
When using the package, make sure to module load openmpi/4.1.4 sqlite geos gdal proj udunits
first.
rgeos
In the shell:
module load geos
In R:
install.packages("rgeos")
When using the package, make sure to module load geos
first.
nloptr
In the shell:
module load cmake
In R:
install.packages("nloptr")
gdtools
In the shell:
module load fontconfig freetype cairo gobject-introspection glib libxcb libxext libxau renderproto libxrender libffi xproto kbproto zlib pixman libx11 libxml2 libxdmcp xextproto pcre libpng
In R:
install.packages("gdtools")
rJava
In the shell:
module load zlib bzip2 libiconv icu4c openjdk
In R:
install.packages("rJava", configure.args="CPPFLAGS='-I${ZLIB_ROOT}/include -I${BZIP2_ROOT}/include -I${LIBICONV_ROOT}/include -I${ICU4C_ROOT}/include' LDFLAGS='-L${ZLIB_ROOT}/lib -L${OPENJDK_ROOT}/lib/server -L${BZIP2_ROOT}/lib -L${LIBICONV_ROOT}/lib -L${ICU4C_ROOT}/lib'")
RcppGSL
In the shell:
module load gsl
In R:
install.packages("RcppGSL")
When using the package, make sure to module load gsl
first.
RcppZiggurat
Create/modify ~/.R/Makevars to include:
CPPFLAGS = -I${GSL_ROOT}/include
LDFLAGS = -L${GSL_ROOT}/lib
In the shell:
module load gsl
In R:
install.packages("RcppZiggurat")
When using the package, make sure to module load gsl
first.
gurobi
In the shell:
module load gurobi/10.0.0
In R:
install.packages("slam")
install.packages("/spack/generic/gurobi/10.0.0/R/gurobi_10.0-0_R_4.2.0.tar.gz", repos = NULL)
When using the package, make sure to module load gurobi/10.0.0
first.
energy
In the shell:
module load gsl
In R:
install.packages("energy")
When using the package, make sure to module load gsl
first.
qqconf
In the shell:
module load openmpi/4.1.4 fftw
In R:
install.packages("qqconf")
When using the package, make sure to module load openmpi/4.1.4 fftw
first.
openblasctl
In R:
install.packages("openblasctl", repos = "https://hpcran.org", configure.args = "--with-openblas-libpath=${OPENBLAS_ROOT}/lib")
float
Create/modify ~/.R/Makevars to include:
CPPFLAGS = -I${OPENBLAS_ROOT}/include
LDFLAGS = -L${OPENBLAS_ROOT}/lib
In R:
install.packages("float")
pbdMPI
Install on a login node.
In the shell:
module load pkgconf openmpi/4.1.4
In R:
install.packages("pbdMPI")
When using the package, make sure to module load openmpi/4.1.4
first.
Rmpi
Install on a login node.
In the shell:
module load pkgconf openmpi/4.1.4
In R:
install.packages("Rmpi")
When using the package, make sure to module load openmpi/4.1.4
first.
Adding compiler flags
When installing R packages from source with compiled programs, you can add custom compiler flags in ~/.R/Makevars. Adding optimization flags may provide a boost in performance for some packages. The following setup is used in the site-wide Makevars.site for each R module:
STDFLAGS = -O2 -pipe -Wall -march=x86-64-v3 -mtune=haswell
CFLAGS = ${STDFLAGS}
C17FLAGS = ${STDFLAGS}
C23FLAGS = ${STDFLAGS}
C90FLAGS = ${STDFLAGS}
C99FLAGS = ${STDFLAGS}
CXXFLAGS = ${STDFLAGS}
CXX11FLAGS = ${STDFLAGS}
CXX14FLAGS = ${STDFLAGS}
CXX17FLAGS = ${STDFLAGS}
CXX20FLAGS = ${STDFLAGS}
CXX20FLAGS = ${STDFLAGS}
CXX23FLAGS = ${STDFLAGS}
FCFLAGS = ${STDFLAGS}
FFLAGS = ${STDFLAGS}
Copy this to ~/.R/Makevars and customize as needed.
You can also target specific CPU microarchitectures if you want. For example, to optimize compiled programs for AMD Zen 3 CPUs, you could change STDFLAGS to:
STDFLAGS = -O2 -pipe -Wall -march=znver3 -mtune=znver3
But note that this means these packages will only work on AMD Zen 3 CPUs (such as the epyc-7513 nodes on the epyc-64 partition on Discovery).