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)
YYYY-MM-DD
format,e.g. "2014-09-17"
. Specify a date on or after "2014-09-17"
. MRAN takes one snapshot per day.snapshotDate
. Defaults to current working directory using getwd()
.R.version
to 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.scanForPackages = FALSE
is 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 = FALSE
if you are certain that all package dependencies are already in the checkpoint folder."~/"
, 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).Rmarkdown
files using the knitr
package.knitr
and rmarkdown
in packages to install.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 setClass
, setRefClass
, setMethod
or setGeneric
will also identify the methods
package as a dependency. Specifically, the function will: ~/.checkpoint
but you can modify the path using the checkpointLocation
argument.
options(repos)
install.packages()
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)
Run the code above in your browser using DataCamp Workspace