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-apt
r-rig
miniforge
1 (See alsomicromamba
provided 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 (
mamba
orconda
)
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
apt
ormamba
(conda
), dependencies outside of R are installed automatically. But, installing R packages via R function (install.packages
) may require separateapt
installations of system libraries that are dependencies. - Generally
r-apt
installs R packages faster thanr-rig
. Therefore, if you want to add R to a container, we recommend tryingr-apt
first. However,r-apt
does not supportubuntu
on arm64 platform, so if you want to useubuntu
on arm64 platform, user-rig
instead. - If you want to install any version of R or use R already installed in the container, you can use
r-rig
to 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
miniforge
for 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-packages
supports package installation from aDESCRIPTION
file via (pak::local_install_deps()
) after container startup.renv-cache
supports package installation via therenv
R 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.↩︎