| checkpoint {checkpoint} | R Documentation |
Together, the checkpoint package and the checkpoint server act as a CRAN time machine. The checkpoint() function installs the packages referenced in the specified project to a local library exactly as they existed at the specified point in time. Only those packages are available to your session, thereby avoiding any package updates that came later and may have altered your results. In this way, anyone using the checkpoint checkpoint() function can ensure the reproducibility of your scripts or projects at any time.
checkpoint(snapshotDate, project = getwd(), R.version, scanForPackages = TRUE, checkpointLocation = "~/", verbose = TRUE, use.knitr, auto.install.knitr = TRUE, scan.rnw.with.knitr = FALSE, forceInstall = FALSE, forceProject = FALSE)
snapshotDate |
Date of snapshot to use in |
project |
A project path. This is the path to the root of the project that references the packages to be installed from the MRAN snapshot for the date specified for |
R.version |
Optional character string, e.g. |
scanForPackages |
If |
checkpointLocation |
File path where the checkpoint library is stored. Default is |
verbose |
If |
use.knitr |
If |
auto.install.knitr |
If |
scan.rnw.with.knitr |
If |
forceInstall |
If |
forceProject |
If |
Checkpoint is called for its side-effects (see the details section), but invisibly returns a list with elements:
files_not_scanned
pkgs_found
pkgs_not_on_mran
pkgs_installed
checkpoint() creates a local library into which it installs a copy of the packages required by your project as they existed on CRAN on the specified snapshot date. Your R session is updated to use only these packages.
To automatically determine all packages used in your project, the function scans all R code (.R, .Rmd, and .Rpres files) for library() and require() statements. In addition, scans for occurrences of code that accesses functions in namespaces using package[::]foo() and package[:::]foo(). Finally, any occurrences of the functions methods::setClass, methods::setRefClass, methods::setMethod or methods::setGeneric will also identify the methods package as a dependency.
Specifically, the function will:
Create a new local snapshot library to install packages. By default this library folder is at ~/.checkpoint but you can modify the path using the checkpointLocation argument.
Update the options for your CRAN mirror and point to an MRAN snapshot using options(repos)
Scan your project folder for all required packages and install them from the snapshot using utils::install.packages()
To reset the checkpoint, simply restart your R session.
You can also use the experimental function unCheckpoint()
By default, checkpoint() uses https to download packages. The default MRAN snapshot defaults to https://mran.microsoft.com/snapshot in R versions 3.2.0 and later, if https support is enabled.
You can modify the default URL. To change the URL, use options(checkpoint.mranUrl = ...).
As a side effect, the checkpoint function writes a log file with information about the downloaded files, in particular the package downloaded and the associated file size in bytes. The log is stored at the root of the checkpointLocation. For example, if checkpointLocation is the user home folder (the default) then the log file is at ~/.checkpoint/checkpoint_log.csv. This file contains columns for:
timestamp
snapshotDate
pkg
bytes
The checkpoint() function stores a marker in the snapshot folder every time the function gets called. This marker contains the system date, thus indicating the the last time the snapshot was accessed. See also getAccessDate(). To remove snapshots that have not been used since a given date, use checkpointRemove()
Other checkpoint functions: checkpointArchives,
checkpointRemove,
getAccessDate,
getValidSnapshots, mranUrl,
setSnapshot, unCheckpoint
## Not run:
# Create temporary project and set working directory
example_project <- paste0("~/checkpoint_example_project_", Sys.Date())
dir.create(example_project, recursive = TRUE)
oldwd <- setwd(example_project)
# Write dummy code file to project
cat("library(MASS)", "library(foreach)",
sep="\n",
file="checkpoint_example_code.R")
# Create a checkpoint by specifying a snapshot date
library(checkpoint)
checkpoint("2014-09-17")
# Check that CRAN mirror is set to MRAN snapshot
getOption("repos")
# Check that library path is set to ~/.checkpoint
.libPaths()
# Check which packages are installed in checkpoint library
installed.packages()
# cleanup
unlink(example_project, recursive = TRUE)
setwd(oldwd)
## End(Not run)