Skip to content

Instantly share code, notes, and snippets.

@dgfitch
Created February 8, 2022 19:40
Show Gist options
  • Save dgfitch/a4c0c90aa90b6c4f48b33041212f8f5f to your computer and use it in GitHub Desktop.
Save dgfitch/a4c0c90aa90b6c4f48b33041212f8f5f to your computer and use it in GitHub Desktop.
Singularity definition file for R
BootStrap: docker
From: ubuntu:18.04
%labels
Maintainer Dan Fitch
R_Version 3.6.3
%apprun R
exec R "${@}"
%apprun Rscript
exec Rscript "${@}"
%apprun Rstudio
exec Rstudio "${@}"
%runscript
exec R "${@}"
%post
# Software versions
export R_VERSION=3.6.3
# Get dependencies
# gnupg is new as of 18.04, required to add apt keys
apt-get update
apt-get install -y --no-install-recommends \
locales \
gnupg
# Run tzdata and force noninteractive
DEBIAN_FRONTEND=noninteractive apt install -y tzdata
# Configure default locale
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen en_US.utf8
/usr/sbin/update-locale LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
# Install R
echo "deb http://cran.r-project.org/bin/linux/ubuntu bionic-cran35/" > /etc/apt/sources.list.d/r.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
apt-get update
apt-get install -y \
r-base=${R_VERSION}* \
r-base-core=${R_VERSION}* \
r-base-dev=${R_VERSION}* \
r-recommended=${R_VERSION}* \
r-base-html=${R_VERSION}* \
r-doc-html=${R_VERSION}* \
libcurl4-openssl-dev \
libssl-dev \
libxml2-dev \
libcairo2-dev \
libxt-dev \
sqlite3 \
libsqlite3-dev
# Add a default CRAN mirror
echo "options(repos = c(CRAN = 'https://cran.rstudio.com/'), download.file.method = 'libcurl')" >> /usr/lib/R/etc/Rprofile.site
# Add a directory for host R libraries
mkdir -p /library
echo "R_LIBS_SITE=/library:\${R_LIBS_SITE}" >> /usr/lib/R/etc/Renviron.site
# Install packages
R --slave -e 'install.packages("pacman", repos="https://cloud.r-project.org/")'
R --slave -e 'install.packages("tidyverse", repos="https://cloud.r-project.org/")'
R --slave -e 'install.packages("psych", repos="https://cloud.r-project.org/")'
# MORE PACKAGES CAN GO HERE WHEEEEE
# Clean up
rm -rf /var/lib/apt/lists/*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment