The Reproducible R Toolkit provides tools to ensure the results of R code are repeatable over time, by anyone. Most R scripts rely on packages, but new versions of packages are released daily. To ensure that results from R are reproducible, it’s important to run R scripts using exactly the same package version in use when the script was written.
The Reproducible R Toolkit provides an R function checkpoint, which ensures that all of the necessary R packages are installed with the correct version. This makes it easy to reproduce your results at a later date or on another system, and makes it easier to share your code with the confidence that others will get the same results you did.
The Reproducible R Toolkit also works in conjunction with the “checkpoint-server”, which makes a daily copy of all CRAN packages, to guarantee that every package version is available to all R developers thereby ensuring reproducibility.
RRT is a collection of R packages and the checkpoint server that together make your work with R packages more reproducible over time by anyone.
To achieve reproducibility, daily snapshots of CRAN are stored on our checkpoint server. At midnight UTC each day, we refresh our mirror of CRAN is refreshed. When the rsync process is complete, the checkpoint server takes and stores a snapshot of the CRAN mirror as it was at that very moment. These daily snapshots can then be accessed on the MRAN website or using the
checkpoint package, which installs and consistently use these packages just as they existed at midnight UTC on a specified snapshot date. Daily snapshots are available as far back as
2014-09-17. For more information, visit the checkpoint server GitHub site.
The goal of the
checkpoint package is to solve the problem of package reproducibility in R. Since packages get updated on CRAN all the time, it can be difficult to recreate an environment where all your packages are consistent with some earlier state. To solve this issue,
checkpoint allows you to install packages locally as they existed on a specific date from the corresponding snapshot (stored on the checkpoint server) and it configures your R session to use only these packages. Together, the
checkpoint package and the checkpoint server act as a CRAN time machine so that anyone using
checkpoint() can ensure the reproducibility of their scripts or projects at any time.
checkpoint is simple:
checkpointhas only a single function,
checkpoint()where you specify the snapshot date.
When you create a checkpoint, the
require()in your code.
This means the remainder of your script will run with the packages from a specific date.
To reset the checkpoint, simply restart your R session.
To create a checkpoint project, you do:
Add a checkpoint to the top of the script:
library(checkpoint) checkpoint("2015-04-26", checkpointLocation = tempdir())
Run the script.
For example, your script may look like this:
library(checkpoint) checkpoint("2015-04-26", checkpointLocation = tempdir()) library(MASS) hist(islands) truehist(islands)
Next you want to run the script. Here is what
## Create a folder to contain the checkpoint ## This is optional - the default is to use ~/.checkpoint dir.create(file.path(tempdir(), ".checkpoint"), recursive = TRUE) ## Create a checkpoint by specifying a snapshot date library(checkpoint)
## ## checkpoint: Part of the Reproducible R Toolkit from Microsoft ## https://mran.microsoft.com/documents/rro/reproducibility/
checkpoint("2017-04-01", project = example_project, checkpointLocation = tempdir())
## Scanning for packages used in this project
## - Discovered 2 packages
## Installing packages used in this project
## - Installing 'MASS'
## checkpoint process complete
Now inspect the results. First, check that your CRAN mirror is set to MRAN snapshot:
##  "https://mran.microsoft.com/snapshot/2017-04-01"
Next, check that the library path is set to
normalizePath(.libPaths(), winslash = "/")
##  "C:/Users/adevries/AppData/Local/Temp/RtmpSWqA0D/.checkpoint/2017-04-01/lib/x86_64-w64-mingw32/3.5.0" ##  "C:/Users/adevries/AppData/Local/Temp/RtmpSWqA0D/.checkpoint/R-3.5.0" ##  "c:/R/R-devel/library"
Finally, check which packages are installed in checkpoint library: