9  Reproducibility

9.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 we track the upstream git url and commit-id in the R package description. This allows renv or similar systems to restore packages in environments that were installed from r-universe. For more details, see this technote: How renv restores packages from r-universe for reproducibility or production.

Furthermore, you can archive fixed versions of an universe which you might use in production or for reproducibility, what we call repository snapshots.

9.2 Repository snapshots

9.2.1 What is a snapshot of an universe?

A snapshot is a standard layout of a few directories consisting of binaries and source packages as well as a few files that index everything. It is a directory of static files that you can host somewhere, and from which you can install fixed versions of packages.

9.2.2 Downloading repository snapshots

The new snapshot API lets you download a full copy of any repository on R-universe. You can use such a snapshot to mirror the entire CRAN-like repository on your own servers, or for example 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 it returns a zip file with all the packages, binaries, and documentation in your repository. If this is more than you need, there are parameters to include e.g. only binaries for certain platforms or certain versions of R, or to create a repository from a subset of the packages in your universe. Explore the parameters on the API tab of any universe, for example: https://ggseg.r-universe.dev/api.

9.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::curl_download("https://jeroen.r-universe.dev/api/snapshot/zip?binaries=4.3", "snapshot.zip")
snapshot <- file.path(tempdir(), 'jeroen')
unzip("snapshot.zip", exdir = snapshot)

# Install packages from the local repository
prefix <- ifelse (.Platform$OS.type == "windows", "file:///", "file://")
repos <- paste0(prefix, normalizePath(snapshot, "/"))
install.packages(c("V8", "mongolite"), repos = repos)