You can customize your R and RStudio environments by building custom containers. These containers will freeze your environment so you always get the same packages, versions, etc.
If you are using bioinformatics R packages you may want to use Conda to install these packages.
You can define your conda requirements either in a flat file called conda-packages.txt or a yaml file called environment.yaml.
# conda-packages.txt
r-base
r-essentials
r-tidyverse
If you use an environment file make sure the environment name is r-env.
Add any additional dependencies to the dependencies block.
name: r-env
channels:
- conda-forge
- bioconda
- defaults
dependencies:
- python=3.10
- jupyter-rsession-proxy
- r-base
- r-essentials
- bioconductor-biocversion
- bioconductor-scran
- pip
# Dockerfile
FROM dabbleofdevops/rocker-conda:4.2.2
# Install system packages
RUN sudo apt update && \
apt install -y \
zlib1g-dev build-essential cmake libglpk-dev libxt-dev libhdf5-dev && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
##################################################
# Option 1 - conda-packages.txt
##################################################
# Copy the conda env definition and install the packages
COPY ./conda-packages.txt ./conda-packages.txt
RUN mamba create --name r-env --file ./conda-packages.txt && \
mamba clean -y --all
##################################################
# Option 1 - environment.yaml
##################################################
# If using an .yaml file use env create
# COPY ./environment.yaml ./
# RUN mamba env create --file ./environment.yaml && \
# mamba clean -y --all
# ADD PATH OF THE r-env
ENV PATH=${CONDA_DIR}/envs/r-env/bin:$PATH
RUN echo "source activate r-env" >> ~/.bashrc
Make sure that you are in the directory as your Dockerfile and conda-packages.txt.
# ls -lah
# Dockerfile
# conda-packages.txt
docker build -t conda-r .
You can keep the images locally, or push them to your dockerhub / ecr (gitlab, etc) accounts.
I usually tag with latest and the days date. Cleary, the only sane way to do this is to use the YYYY-MM-DD format.
export IMAGE="conda-r"
docker tag ${IMAGE} docker-org/remote-repo:latest
docker tag ${IMAGE} docker-org/remote-repo:DATE ## YYYY.MM.DD
docker push docker-org/remote-repo:latest
docker push docker-org/remote-repo:DATE. ## YYYY.MM.DD
Optionally, you can convert your docker image to a singularity image and store on NFS or S3. This is a more common scenario for HPCs.
This assumes we have a local image named conda-r.
export IMAGE="conda-r"
singularity pull ${IMAGE}.sif docker://${IMAGE}