title: Installing a specific version of R from an Apt repository
body: <p>R volunteers currently maintain Ubuntu package repositories for R ~3.5 and ~4.0. For Bionic Beaver, these are:</p>
  <ul>
  <li><a href="https://cloud.r-project.org/bin/linux/ubuntu/bionic-cran35/" rel="nofollow noreferrer">https://cloud.r-project.org/bin/linux/ubuntu/bionic-cran35/</a></li>
  <li><a href="https://cloud.r-project.org/bin/linux/ubuntu/bionic-cran40/" rel="nofollow noreferrer">https://cloud.r-project.org/bin/linux/ubuntu/bionic-cran40/</a></li>
  </ul>
  <p>I am building separate Singularity containers, into which I need very specific versions of R installed; which appear to be provided in these repositories. Specifically, I'm looking to build containers containing R versions 3.6.1, 4.0.3 and 4.1.0; one container per version.</p>
  <p>I do this, in the container build script, by first adding the appropriate Apt source, then running the install with a pinned version. I noticed that I could only get it to run if I use the precise version numbers listed in the package repository <em>and</em> also include <code>r-recommended</code> at the same version. For example, for R 3.6.1:</p>
  <pre><code>apt install -y r-base=3.6.1-3bionic r-recommended=3.6.1-3bionic
  </code></pre>
  <p>This correctly installs <code>r-base</code> and <code>r-recommended</code> at the given versions. However, when I run the containerised R, R is actually reporting itself to be at the latest version provided by those repositories (3.6.3, 4.1.0 and 4.1.0, respectively). Presumably, given <code>r-base</code> is correct, this may even suggest them to be in a broken state.</p>
  <p>Looking through Apt's output, it's clear that many other <code>r-*</code> packages are defaulting to the latest versions, rather than the versions I specified. In an attempt to get around this, I tried explicitly setting the versions on all the packages that are defaulting to the latest version. For example, again with R 3.6.1:</p>
  <pre><code>apt install -y r-base=3.6.1-3bionic \
                 r-base-core=3.6.1-3bionic \
                 r-base-dev=3.6.1-3bionic \
                 r-base-html=3.6.1-3bionic \
                 r-doc-html=3.6.1-3bionic \
                 r-recommended=3.6.1-3bionic
  </code></pre>
  <p>However, this refuses to work, complaining about conflicts with other packages it's trying to install (<code>r-cran-*</code> packages, IIRC).</p>
  <p>I don't know if this is an Apt-thing, an R-thing, or something to do with their repositories. Is there a way I can get these specific versions installed from the official sources, without having to build anything myself? (If not, what's the point of them keeping the older versions in their repositories?)</p>