8 Reproducibility
8.1 Does R-universe archive old versions of packages? How does it work with renv?
R-universe does not archive old versions of packages, but it tracks the upstream git URL and commit ID in the R package description. This allows tools like renv
to restore packages in environments that were installed from R-universe. For more details, see this tech note: How renv restores packages from r-universe for reproducibility or production.
You can also archive fixed versions of a universe for production or reproducibility, using what we call repository snapshots.
8.2 Repository snapshots
8.2.1 What is a snapshot of an universe?
A snapshot is a standard layout of a few directories consisting of static files containing binaries, source packages, and indexing files.
Snapshots allow you to host fixed versions of packages and install them as needed.
8.2.2 Downloading repository snapshots
The snapshot API lets you download a full copy of any repository on R-universe.
You can use this snapshot to mirror the CRAN-like repository on your own servers or to build a stable, validated release of your package suite.
The API endpoint is /api/snapshot
and has several options to filter content. By default, the endpoint returns a zip file with all the repository’s packages, binaries, and documentation. If needed, you can filter the content to include only specific binaries, R versions, or subsets of packages.
Explore the API parameters for your universe, for instance https://ggseg.r-universe.dev/api.
8.2.3 Using snapshots
A CRAN-like R package repository is essentially a static directory of package files and indexes, with a specific naming structure. R-universe automatically builds and updates all these files based on a registry of packages and upstream git sources. Once everything is generated, you can simply copy the entire folder elsewhere, and have a frozen CRAN-like package repository on that server. For instance…
An organization could host a mirror of their repository internally in their intranet. They could update the mirror every day, every month, etc.
You could create a GitHub Action which regularly downloads a snapshot from R-universe to publish on github-pages. Here is a minimal example of such an action: https://github.com/jeroen/backup.
Note how the aforementioned action is very fast: downloading and extracting the snapshot from R-universe only takes a few seconds. So this is easily something that could be done on demand, or automatically on a regular basis.
You can also install packages in R directly from a local snapshot folder, by prefixing the path that you pass to install.packages
with file://
(Windows paths need to be normalized to look more unixy):
# Download and extract the snapshot
::curl_download("https://jeroen.r-universe.dev/api/snapshot/zip?binaries=4.3", "snapshot.zip")
curl<- file.path(tempdir(), 'jeroen')
snapshot unzip("snapshot.zip", exdir = snapshot)
# Install packages from the local repository
<- ifelse (.Platform$OS.type == "windows", "file:///", "file://")
prefix <- paste0(prefix, normalizePath(snapshot, "/"))
repos install.packages(c("V8", "mongolite"), repos = repos)