Learn R Programming

renv (version 0.6.0-73)

snapshot: Snapshot a Project

Description

Call snapshot() to create a lockfile capturing the state of a project's R package dependencies. The lockfile can be used to later restore these project's dependencies as required. See the lockfile documentation for more details on the structure of a lockfile.

Usage

snapshot(project = NULL, ..., library = NULL,
  lockfile = file.path(project, "renv.lock"),
  type = settings$snapshot.type(project = project),
  confirm = interactive())

Arguments

project

The project directory. If NULL, then the active project will be used. If no project is currently active, then the current working directory is used instead.

...

Optional arguments; reserved for future expansion.

library

The R libraries to snapshot. When NULL, the active R libraries (as reported by .libPaths()) are used.

lockfile

The location where the generated lockfile should be written. By default, the lockfile is written to a file called renv.lock in the project directory. When NULL, the lockfile (as an R object) is returned directly instead.

type

The type of snapshot to perform. See Snapshot Type for more details. When NULL (the default), a "packrat"-style snapshot is performed.

confirm

Boolean; prompt the user before taking any action?

Snapshot Type

Depending on how you prefer to manage dependencies, you might prefer selecting a different snapshot mode. The modes available are as follows:

"simple"

All packages within the active libraries are included in the lockfile. This is the quickest and simplest method, but may lead to packages (e.g. development dependencies) entering the lockfile, which can be undesired.

"packrat"

Perform a Packrat-style snapshot. The intersection of packages discovered in your R libraries, alongside those discovered by renv::dependencies(), will enter the lockfile. This helps ensure that only the packages you are using will enter the lockfile, but may be slower if your project contains a large number of files. The snapshot.timeout config option can be used to control the maximum amount of time that can be spent discovering dependencies.

"custom"

Like "packrat", but use a custom user-defined filter instead. The filter should be specified by the R option renv.snapshot.filter, and should either be a character vector naming a function (e.g. "package::method"), or be a function itself. The function should only accept one argument (the project directory), and should return a vector of package names to include in the lockfile.

See Also

Other reproducibility: lockfile, restore

Examples

Run this code
# NOT RUN {
# disable automatic snapshots
auto.snapshot <- getOption("renv.config.auto.snapshot")
options(renv.config.auto.snapshot = FALSE)

# initialize a new project (with an empty R library)
renv::init(bare = TRUE)

# install digest 0.6.19
renv::install("digest@0.6.19")

# save library state to lockfile
renv::snapshot()

# remove digest from library
renv::remove("digest")

# check library status
renv::status()

# restore lockfile, thereby reinstalling digest 0.6.19
renv::restore()

# restore automatic snapshots
options(renv.config.auto.snapshot = auto.snapshot)

# }

Run the code above in your browser using DataLab