R package installation guide

A guide for installing certain R packages using the modules available on CARC systems.

The following instructions are based on the R 4.2.1 module:

module purge
module load gcc/11.3.0
module load openblas/0.3.20
module load r/4.2.1

Older R versions may require different steps.

For some R packages, the modules that need to be loaded to install the package may also need to be loaded in order to load the R package.

R packages

XML

module load pkgconf libxml2 xz libiconv

And install:

install.packages("XML")

xml2

module load libxml2

And install:

install.packages("xml2")

openssl

module load openssl

And install:

install.packages("openssl")

curl

module load curl

And install:

install.packages("curl")

RCurl

module load curl libxml2

And install:

install.packages("RCurl")

httpuv

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${ZLIB_ROOT}/include
LDFLAGS = -L${ZLIB_ROOT}/lib

Then:

module load zlib automake autoconf libtool m4

And install:

install.packages("httpuv")

git2r

module load git libgit2

And install:

install.packages("git2r")

Cairo

module load cairo fontconfig freetype xproto libx11 libxt harfbuzz graphite2 icu4c glib libpng libjpeg libtiff zlib
export CAIRO_CFLAGS="-I$CAIRO_ROOT/include/cairo -I$FONTCONFIG_ROOT/include -I$FREETYPE_ROOT/include/freetype2 -I$XPROTO_ROOT/include -I$LIBX11_ROOT/include -I$LIBXT_ROOT/include -I$HARFBUZZ_ROOT/include -I$GRAPHITE2_ROOT/include -I$ICU4C_ROOT/include -I$GLIB_ROOT/include -I$LIBPNG_ROOT/include -I$LIBJPEG_ROOT/include -I$LIBTIFF_ROOT/include -I$ZLIB_ROOT/include"
export CAIRO_LIBS="-L$CAIRO_ROOT/lib -lcairo -L$FONTCONFIG_ROOT/lib -L$FREETYPE_ROOT/lib -L$XPROTO_ROOT/lib -L$LIBX11_ROOT/lib -L$LIBXT_ROOT/lib -L$HARFBUZZ_ROOT/lib -L$GRAPHITE2_ROOT/lib -L$ICU4C_ROOT/lib -L$GLIB_ROOT/lib -L$LIBPNG_ROOT/lib -L$LIBJPEG_ROOT/lib -L$LIBTIFF_ROOT/lib -L$ZLIB_ROOT/lib"

And install:

install.packages("Cairo")

systemfonts

module unload pkgconf
module load fontconfig freetype libxml2

And install:

install.packages("systemfonts")

textshaping

module load freetype harfbuzz fribidi libpng
wget https://cran.r-project.org/src/contrib/textshaping_0.3.6.tar.gz
R CMD INSTALL --configure-vars="INCLUDE_DIR='$HARFBUZZ_ROOT/include/harfbuzz -I$FREETYPE_ROOT/include/freetype2 -I$FRIBIDI_ROOT/include/fribidi -I$LIBPNG_ROOT/include' LIB_DIR='$HARFBUZZ_ROOT/lib -L$FREETYPE_ROOT/lib -L$FRIBIDI_ROOT/lib -L$LIBPNG_ROOT/lib'" textshaping_0.3.6.tar.gz

ragg

module load freetype libpng libtiff libjpeg-turbo bzip2
wget https://cloud.r-project.org/src/contrib/ragg_1.2.2.tar.gz
R CMD INSTALL --configure-vars="INCLUDE_DIR='$FREETYPE_ROOT/include/freetype2 -I$LIBPNG_ROOT/include -I$LIBTIFF_ROOT/include -I$LIBJPEG_TURBO_ROOT/include -I$BZIP2_ROOT/include' LIB_DIR='$FREETYPE_ROOT/lib -L$LIBPNG_ROOT/lib -L$LIBTIFF_ROOT/lib -L$LIBJPEG_TURBO_ROOT/lib64 -L$BZIP2_ROOT/lib'" ragg_1.2.2.tar.gz

png

module load libpng

And install:

install.packages("png")

jpeg

module load libjpeg
export JPEG_CFLAGS=-I$LIBJPEG_ROOT/include
export JPEG_LIBS=-L$LIBJPEG_ROOT/lib

And install:

install.packages("jpeg")

rsvg

module load pkgconf librsvg 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

And install:

install.packages("rsvg")

Cairo

module load cairo fontconfig freetype xproto libx11 libxt harfbuzz graphite2 icu4c glib libpng libjpeg libtiff zlib
export CAIRO_CFLAGS="-I$CAIRO_ROOT/include/cairo -I$FONTCONFIG_ROOT/include -I$FREETYPE_ROOT/include/freetype2 -I$XPROTO_ROOT/include -I$LIBX11_ROOT/include -I$LIBXT_ROOT/include -I$HARFBUZZ_ROOT/include -I$GRAPHITE2_ROOT/include -I$ICU4C_ROOT/include -I$GLIB_ROOT/include -I$LIBPNG_ROOT/include -I$LIBJPEG_ROOT/include -I$LIBTIFF_ROOT/include -I$ZLIB_ROOT/include"
export CAIRO_LIBS="-L$CAIRO_ROOT/lib -lcairo -L$FONTCONFIG_ROOT/lib -L$FREETYPE_ROOT/lib -L$XPROTO_ROOT/lib -L$LIBX11_ROOT/lib -L$LIBXT_ROOT/lib -L$HARFBUZZ_ROOT/lib -L$GRAPHITE2_ROOT/lib -L$ICU4C_ROOT/lib -L$GLIB_ROOT/lib -L$LIBPNG_ROOT/lib -L$LIBJPEG_ROOT/lib -L$LIBTIFF_ROOT/lib -L$ZLIB_ROOT/lib"

And install:

install.packages("Cairo")

igraph

module load libxml2

And install:

install.packages("igraph")

ncdf4

module load openmpi/4.1.4 netcdf-c

And install:

install.packages("ncdf4")

hdf5r

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${ZLIB_ROOT}/include
LDFLAGS = -L${ZLIB_ROOT}/lib

Then:

module load openmpi/4.1.4 hdf5 zlib

And install:

install.packages("hdf5r")

bigmemory

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${LIBUUID_ROOT}/include
LDFLAGS = -L${LIBUUID_ROOT}/lib

Then:

module load libuuid

And install:

install.packages("bigmemory")

units

module load openmpi/4.1.4 sqlite geos gdal proj udunits

And install

install.packages("units", configure.args = "--with-udunits2-lib=${UDUNITS_ROOT}/lib --with-udunits2-include=${UDUNITS_ROOT}/include")

udunits2

module load openmpi/4.1.4 sqlite geos gdal proj udunits

And install:

install.packages("udunits2", configure.args = "--with-udunits2-lib=${UDUNITS_ROOT}/lib --with-udunits2-include=${UDUNITS_ROOT}/include")

rgdal

module load openmpi/4.1.4 sqlite geos gdal proj udunits

And install:

install.packages("rgdal")

sf

module load openmpi/4.1.4 sqlite geos gdal proj udunits openssl

And install:

install.packages("sf", configure.args = "--with-sqlite3-lib=${SQLITE_ROOT}/lib")

terra

module load openmpi/4.1.4 sqlite geos gdal proj udunits

And install:

install.packages("terra", configure.args = "--with-sqlite3-lib=${SQLITE_ROOT}/lib")

rgeos

module load geos

And install:

install.packages("rgeos")

nloptr

module load cmake

And install:

install.packages("nloptr")

gdtools

module load pkgconf fontconfig freetype cairo gobject-introspection glib libxcb libxext libxau renderproto libxrender libffi xproto kbproto zlib pixman libx11 libxml2 libxdmcp xextproto pcre

And install:

install.packages("gdtools")

rJava

module load bzip2 libiconv icu4c openjdk

And install:

install.packages("rJava", configure.args="CPPFLAGS='-I${BZIP2_ROOT}/include -I${LIBICONV_ROOT}/include -I${ICU4C_ROOT}/include' LDFLAGS='-L${OPENJDK_ROOT}/lib/server -L${BZIP2_ROOT}/lib -L${LIBICONV_ROOT}/lib -L${ICU4C_ROOT}/lib'")

RcppGSL

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${GSL_ROOT}/include
LDFLAGS = -L${GSL_ROOT}/lib

Then:

module load gsl

And install:

install.packages("RcppGSL")

RcppZiggurat

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${GSL_ROOT}/include
LDFLAGS = -L${GSL_ROOT}/lib

Then:

module load gsl

And install:

install.packages("RcppZiggurat")

gurobi

module load gurobi/10.0.0

And install:

install.packages("slam")
install.packages("/spack/generic/gurobi/10.0.0/R/gurobi_10.0-0_R_4.2.0.tar.gz", repos = NULL)

openblasctl

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

And install:

install.packages("float")

pbdMPI

module load openmpi/4.1.4

And install:

install.packages("pbdMPI")

Bioconductor packages

Rhtslib

Create/modify ~/.R/Makevars to include:

CPPFLAGS = -I${BZIP2_ROOT}/include -I${XZ_ROOT}/include -I${CURL_ROOT}/include
LDFLAGS = -L${BZIP2_ROOT}/lib -L${XZ_ROOT}/lib -L${CURL_ROOT}/lib

Then:

module load bzip2 xz curl

And install:

BiocManager::install("Rhtslib")