Install R and package 'devtools' in Base-Dockerfile images: a step-by-step guide

1. Select the right Ubuntu Archive Mirror

First of all, in order to create a robust and sustainable Linux environment, we have to use mirrors that are fast and up-to-date.

For that, I recommend installing apt-select, it can target your specified country to find the least latency to mirrors in the country's mirror list at mirrors.ubuntu.com.

To do so, we have to install it first. Since we will be using docker images created by Base-Dockerfile, some extra steps had to be taken because I purposely simplified the image to not include many bulky libraries and tools, including pip. So we will have to install that first.

apt install -y python3-pip

Then we can install apt-select

pip3 install apt-select

Now you can select the optimal Ubuntu Archive Mirror based on your physical location.

apt-select --country CA
cp /etc/apt/sources.list /etc/apt/sources.list.backup && mv sources.list /etc/apt/

2. Install R and devtools package

To install devtools package, we have to install a few system-wide dependencies first. Note that this also applies to many other package installation including tidyverse, since these three libraries are used by and required by many packages.

apt install -y libssl-dev libxml2-dev libcurl4-openssl-dev

Then we can install R:

apt install -y r-base

Then in an R session, install devtools package:

install.packages("devtools")

You should be all set by now!