3

R volunteers currently maintain Ubuntu package repositories for R ~3.5 and ~4.0. For Bionic Beaver, these are:

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.

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 and also include r-recommended at the same version. For example, for R 3.6.1:

apt install -y r-base=3.6.1-3bionic r-recommended=3.6.1-3bionic

This correctly installs r-base and r-recommended 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 r-base is correct, this may even suggest them to be in a broken state.

Looking through Apt's output, it's clear that many other r-* 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:

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

However, this refuses to work, complaining about conflicts with other packages it's trying to install (r-cran-* packages, IIRC).

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?)

Xophmeister
  • 8,884
  • 4
  • 44
  • 87
  • 1
    Probably worth a look [r-base and r-recommended](https://stackoverflow.com/questions/9700799/difference-between-r-base-and-r-recommended-packages). – Chris Jul 22 '21 at 15:15
  • Thank you :) OK, so `r-base` is a metapackage containing `r-base-core` and `r-recommends`, amongst other things. So if I _just_ install `r-base-core` with `--no-install-recommends` -- and maybe the docs, pinned to the same version -- then it works! – Xophmeister Jul 22 '21 at 15:38
  • 1
    And complete the virtuous circle by writing up your answer and accepting it, as answered questions attract more searchers with similar problems, after confirming it meets your needs and expectations. – Chris Jul 22 '21 at 15:41
  • First line is wrong: not "the R Project". This is a purely volunteer iniative by Michael Rutter (mostly, with assist by me via the underlying Debian package). – Dirk Eddelbuettel Jul 22 '21 at 15:52
  • 1
    @DirkEddelbuettel Edited; sorry, I was unaware. I had incorrectly assumed it being hosted under r-project.org meant there was some official involvement from the project. – Xophmeister Jul 22 '21 at 16:04

1 Answers1

4

Thanks to @Chris' tip-off, the structure of said R packages is important to understand.

r-base is a metapackage which includes, amongst other things, r-base-core and r-recommended. r-recommended is another metapackage which includes a suite of recommended R packages, which introduce the incompatibility when trying to pin to versions.

For just the R binaries and the documentation, pinned to a specific ${VERSION}, this will do the trick:

apt install -y --no-install-recommends \
  r-base-core=${VERSION} \
  r-base-html=${VERSION} \
  r-doc-html=${VERSION}

If you want to build packages, you'd also want r-base-dev=${VERSION} in there.

Xophmeister
  • 8,884
  • 4
  • 44
  • 87
  • 2
    Which is, coincidentally, code you could have copied basically verbatim from the rocker r-base container for Docker I maintain (and which is also the official r-base image). – Dirk Eddelbuettel Jul 22 '21 at 15:53
  • On focal fossa seeking the old R version 4.1.2, this answer fails with errors like `E: Version '4.1.2' for 'r-base-core' was not found`. I tried adding the appropriate apt source according to [these instructions](https://cran.r-project.org/bin/linux/ubuntu/olderreleasesREADME.html), meaning I ran `sudo add-apt-repository "deb https://cloud.r-project.org/bin/linux/ubuntu $(lsb_release -cs)-cran40/"`. Do you have any suggestions about how to get it working? – eric_kernfeld May 23 '23 at 20:02