Configures R session to use packages as they existed on CRAN at time of snapshot.
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 = system.file(package = "knitr") != "", auto.install.knitr = TRUE, scan.rnw.with.knitr = FALSE)
- Date of snapshot to use in
"2014-09-17". Specify a date on or after
"2014-09-17". MRAN takes one snapshot per day.
- 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
snapshotDate. Defaults to current working directory using
- Optional character string, e.g. "3.1.2". If specified, compares the current
R.versionto the specified R.version. If these differ, stops processing with an error, making no changes to the system. Specifically, if the check fails, the library path is NOT modified. This argument allows the original script author to specify a specific version of R to obtain the desired results.
- If TRUE, scans for packages in project folder (see details). If FALSE, skips the scanning process. A use case for
scanForPackages = FALSEis to skip the scanning and installation process, e.g. in production environments with a large number of R scripts in the project. Only set
scanForPackages = FALSEif you are certain that all package dependencies are already in the checkpoint folder.
- File path where the checkpoint library is stored. Default is
"~/", i.e. the user's home directory. A use case for changing this is to create a checkpoint library on a portable drive (e.g. USB drive).
- If TRUE, displays progress messages.
- If TRUE, parses all
Rmarkdownfiles using the
- If TRUE and the project contains rmarkdown files, then automatically included the packages
rmarkdownin packages to install.
- If TRUE, uses
.Rnwfiles, otherwise use
Checkpoint is called for its side-effects (see the details section), but invisibly returns a list with elements:
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 (
.Rpres files) for
require() statements. In addition, scans for occurrences of code that accesses functions in namespaces using
foo(). Finally, any occurrences of the functions
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
~/.checkpointbut you can modify the path using the
- Update the options for your CRAN mirror and point to an MRAN snapshot using
- Scan your project folder for all required packages and install them from the snapshot using
Resetting the checkpoint
To reset the checkpoint, simply restart your R session.
Changing the default MRAN url
checkpoint uses https by default to download packages (see https://www.r-consortium.org/news/blogs/2015/08/best-practices-using-r-securely).
checkpoint Defaults to https://mran.microsoft.com/snapshot by default 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 = ...)
## 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)