'Creating Dockerfile container containing R (tidyverse) and Python (rpy2 configured with R)

I would like to create a Dockerfile so that when a user specifies mode=validation, both R with tidyverse and Python with rpy2 (configured with R) and other Python dependencies are installed. I'm having trouble with creating this containerized environment and I'm not sure if the pre-built rpy2 Docker container is currently working.

Here is my current Dockerfile. Any help would be appreciated!

ARG mode

FROM ubuntu:latest as replication
ENV DEBIAN_FRONTEND=noninteractive
ENV MODE="replication"
RUN apt-get update && apt-get install -y --no-install-recommends build-essential python3.6 python3-pip python3-setuptools python3-dev
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip3 install -r requirements.txt
COPY . /app

FROM rocker/tidyverse:4.0.1 AS validation
ENV MODE="validation"
RUN apt-get update && apt-get install -y --no-install-recommends build-essential r-base r-cran-randomforest python3.6 python3-pip python3-setuptools python3-dev
WORKDIR /app
COPY requirements.txt /app/requirements.txt
COPY requirements.R /app/requirements.R
# pre install the packages during build
RUN Rscript requirements.R

FROM ${mode} AS final
RUN echo "VAR is equal to ${VAR}"


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source