1 Overview
The Rocker Project provides some Dev Container Features for installing R or installing software often used with R.
- Source repository: rocker-org/devcontainer-features
You can find them on the Dev Containers site, the GitHub Codespaces Dev Container Editor, or, VSCode Dev Containers.
These can be used to easily configure R on containers without R installed, or to make containers for R even more useful. And of course, we can use them independently of R! (except for the Features to install R)
For example, install R on the default image of Codespaces by editing the devcontainer.json file as follows:
.devcontainer/devcontainer.json
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/rocker-org/devcontainer-features/r-apt:latest": {}
}
}There is also a repository that can be used to try Dev Containers on GitHub Codespaces immediately.
Check the source repository for details on each Feature.
2 Install R on Dev Containers
There are some Dev Container Features that can be used to install R.
r-aptr-rigminiforge1 (See alsomicromambaprovided by mamba-org)
Each of these installations of R will be configured to allow installation of R binary packages in the following ways.
- System package management system (
apt) - Posit Public Package Manager (R functions e.g.
install.packages)2 - conda-forge (
mambaorconda)
Therefore, which of these you use to install R may depend on which method you wish to use to install the R binary packages.
Some tips for choosing:
- When installing R packages via
aptormamba(conda), dependencies outside of R are installed automatically. But, installing R packages via R function (install.packages) may require separateaptinstallations of system libraries that are dependencies. - Generally
r-aptinstalls R packages faster thanr-rig. Therefore, if you want to add R to a container, we recommend tryingr-aptfirst. - If you want to install any version of R or use R already installed in the container, you can use
r-rigto install any version of R or only the R package without installing R. - If you want to install packages that exist in the conda-forge, you can use
miniforgefor fast installation withmamba.
3 Install R packages on Dev Containers
Several Dev Container Features allow R package installation to be defined on devcontainer.json.
These support package installation via apt or R function (pak::pak()).
There are also r-dependent-packages and renv-cache.
r-dependent-packagessupports package installation from aDESCRIPTIONfile via (pak::local_install_deps()) after container startup.renv-cachesupports package installation via therenvR package after container startup.
4 See also
Footnotes
This Feature does not directly install R, but it configures mamba so we can use mamba to install R.↩︎
Of the amd64 and arm64 Debian and Ubuntu platforms that can use
r-rig, only amd64 Ubuntu can use Posit Public Package Manager, and Posit Public Package Manager will be not configured on the other platforms.↩︎