1 Quick reference
- Source repository: rocker-org/rocker-versioned2
- Dockerfile
- tags
- Published image details: rocker-org/rocker-versioned2’s wiki
- Non-root default user: not exist
2 Overview
rocker/r-ver
is alternate image to r-base
, with an emphasis on reproducibility.
Compared to r-base
,
- Builds on Ubuntu LTS rather than Debian and system libraries are tied to the Ubuntu version. Images will use the most recent LTS available at the time when the corresponding R version was released.
- Since compatibility problems are likely to occur immediately after the release of a new Ubuntu LTS, the version to be used is the one that is at least 90 days past release.
rocker/r-ver:4.0.0
is based on Ubuntu 20.04 (ubuntu:focal
) because no interval was set at the time of the Ubuntu 20.04 release.
- Since compatibility problems are likely to occur immediately after the release of a new Ubuntu LTS, the version to be used is the one that is at least 90 days past release.
- Installs a fixed version of R itself from source, rather than whatever is already packaged for Ubuntu (the
r-base
stack gets the latest R version as a binary from Debian unstable). - The only platforms available are
linux/amd64
andlinux/arm64
(arm64 images are experimental and only available forrocker/r-ver
4.1.0 or later). - Set the Posit Public Package Manager (P3M, a.k.a RStudio Package Manager, RSPM) as default CRAN mirror. For the amd64 platform, RSPM serves compiled Linux binaries of R packages and greatly speeds up package installs.
- Non-latest R version images installs all R packages from a fixed snapshot of CRAN mirror at a given date. This setting ensures that the same version of the R package is installed no matter when the installation is performed.
- Provides images that are generally smaller than the
r-base
series.
This document is for R 4.0.0 >= images. Please check the rocker-org/rocker-versioned repository for R <= 3.6.3 images.
4 How to use
4.1 Switch the default CRAN mirror
As explained in the overview, rocker/r-ver
may have set a past CRAN snapshot as the default repository. This is determined by the options set in the Rprofile
. To use a different CRAN mirror, simply write a new setting in the Rprofile
.
For example, the following Dockerfile sets the default repository to CRAN.
Dockerfile
FROM rocker/r-ver:4
RUN echo 'options(repos = c(CRAN = "https://cloud.r-project.org"))' >>"${R_HOME}/etc/Rprofile.site"
To do the same thing by a non-root user in a container, for example, the following command can be used.
Terminal
echo 'options(repos = c(CRAN = "https://cloud.r-project.org"))' | sudo sh -c 'cat - >>"${R_HOME}/etc/Rprofile.site"'
We can also use the script setup_R.sh
included in rocker/r-ver
.
Dockerfile
FROM rocker/r-ver:4
RUN /rocker_scripts/setup_R.sh https://packagemanager.posit.co/cran/__linux__/jammy/2023-01-29
The advantage of using this script is that if you specify a URL for binary installation from Posit Public Package Manager (P3M), it will rewrite the URL and switch to source installation on non-amd64 platforms.
For example, in the above example, https://packagemanager.posit.co/cran/__linux__/jammy/2023-01-29
is set for the amd64 platform, but https://packagemanager.posit.co/cran/2023-01-29
is set for the arm64 platform as the default CRAN mirror.
Or, if you want to temporarily change the CRAN mirror during an R session, use the options()
function.
A common use case is when developing an R package and using the devtools::check()
function; if the CRAN mirror is not changed from the default, an error like cannot open URL 'packagemanager.posit.co/cran/__linux__/jammy/latest/web/packages/packages.rds': HTTP status was '404 Not Found'
may occur.
R Terminal
options(repos = c(CRAN = "https://cloud.r-project.org"))
::check() devtools
It is also possible to set up P3M and CRAN at the same time to achieve both binary installation and successful the devtools::check()
function as follows. (rocker-org/rocker-versioned2#658)
Dockerfile
FROM rocker/r-ver:4
RUN echo 'options(repos = c(P3M = "https://packagemanager.posit.co/cran/__linux__/jammy/latest", CRAN = "https://cloud.r-project.org"))' >>"${R_HOME}/etc/Rprofile.site"
4.2 Selecting the BLAS implementation used by R
By default rocker/r-ver
uses the OpenBLAS implementation for Linear Algebra1. But it is possible to switch for the reference BLAS implementation (as provided by the Debian package libblas-dev
) using the Shared BLAS setup2.
Calling Python numpy
by the reticulate
package on R using OpenBLAS may cause a segfault. This causes an error when trying to use Python packages like matplotlib
or scikit-learn
. (rocker-org/rocker-versioned2#471, numpy/numpy#21643)
If this error occurs, change the BLAS used by R to libblas as described below.
4.2.1 Checking which BLAS is in use
You can see the current BLAS configuration for R by using sessionInfo()
function in R console.
R Terminal
sessionInfo()
#> R version 4.2.0 (2022-04-22)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Ubuntu 20.04.4 LTS
#>
#> Matrix products: default
#> BLAS: /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
#> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/liblapack.so.3
Here for instance R uses OpenBLAS.
4.2.2 Switching BLAS implementations
You can switch BLAS used by R with the Debian update-alternatives
script:
Terminal
ARCH=$(uname -m)
update-alternatives --set "libblas.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/blas/libblas.so.3"
update-alternatives --set "liblapack.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/lapack/liblapack.so.3"
Terminal
ARCH=$(uname -m)
update-alternatives --set "libblas.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/openblas-pthread/libblas.so.3"
update-alternatives --set "liblapack.so.3-${ARCH}-linux-gnu" "/usr/lib/${ARCH}-linux-gnu/openblas-pthread/liblapack.so.3"