Debian Codegraph @

man/snapshot.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/snapshot.R
3 \name{snapshot}
4 \alias{snapshot}
5 \title{Record current state of the project library in the lockfile}
6 \usage{
7 snapshot(
8 project = NULL,
9 ...,
10 library = NULL,
11 lockfile = paths$lockfile(project = project),
12 type = settings$snapshot.type(project = project),
13 dev = NULL,
14 repos = getOption("repos"),
15 packages = NULL,
16 exclude = NULL,
17 prompt = interactive(),
18 update = FALSE,
19 force = FALSE,
20 reprex = FALSE
21 )
22 }
23 \arguments{
24 \item{project}{The project directory. If \code{NULL}, then the active project will
25 be used. If no project is currently active, then the current working
26 directory is used instead.}
27
28 \item{...}{Unused arguments, reserved for future expansion. If any arguments
29 are matched to \code{...}, renv will signal an error.}
30
31 \item{library}{The \R libraries to snapshot. When \code{NULL}, the active \R
32 libraries (as reported by \code{.libPaths()}) are used.}
33
34 \item{lockfile}{The location where the generated lockfile should be written.
35 By default, the lockfile is written to a file called \code{renv.lock} in the
36 project directory. When \code{NULL}, the lockfile (as an \R object) is returned
37 directly instead.}
38
39 \item{type}{The type of snapshot to perform:
40 \itemize{
41 \item \code{"implicit"}, (the default), uses all packages captured by \code{\link[=dependencies]{dependencies()}}.
42 \item \code{"explicit"} uses packages recorded in \code{DESCRIPTION}.
43 \item \code{"all"} uses all packages in the project library.
44 \item \code{"custom"} uses a custom filter.
45 }
46
47 See \strong{Snapshot types} below for more details.}
48
49 \item{dev}{Boolean; include development dependencies? These packages are
50 typically required when developing the project, but not when running it
51 (i.e. you want them installed when humans are working on the project but
52 not when computers are deploying it).
53
54 Development dependencies include packages listed in the \code{Suggests} field
55 of a \code{DESCRIPTION} found in the project root, and roxygen2 or devtools if
56 their use is implied by other project metadata. They also include packages
57 used in \verb{~/.Rprofile} if \code{config$user.profile()} is \code{TRUE}.}
58
59 \item{repos}{The \R repositories to be recorded in the lockfile. Defaults
60 to the currently active package repositories, as retrieved by
61 \code{getOption("repos")}.}
62
63 \item{packages}{A vector of packages to be included in the lockfile. When
64 \code{NULL} (the default), all packages relevant for the type of snapshot being
65 performed will be included. When set, the \code{type} argument is ignored.
66 Recursive dependencies of the specified packages will be added to the
67 lockfile as well.}
68
69 \item{exclude}{A vector of packages to be explicitly excluded from the lockfile.
70 Note that transitive package dependencies will always be included, to avoid
71 potentially creating an incomplete / non-functional lockfile.}
72
73 \item{prompt}{Boolean; prompt the user before taking any action? For backwards
74 compatibility, \code{confirm} is accepted as an alias for \code{prompt}.}
75
76 \item{update}{Boolean; if the lockfile already exists, then attempt to update
77 that lockfile without removing any prior package records.}
78
79 \item{force}{Boolean; force generation of a lockfile even when pre-flight
80 validation checks have failed?}
81
82 \item{reprex}{Boolean; generate output appropriate for embedding the lockfile
83 as part of a \href{https://tidyverse.org/help/#reprex}{reprex}?}
84 }
85 \value{
86 The generated lockfile, as an \R object (invisibly). Note that
87 this function is normally called for its side effects.
88 }
89 \description{
90 Call \code{renv::snapshot()} to update a \link{lockfile} with the current state of
91 dependencies in the project library. The lockfile can be used to later
92 \link{restore} these dependencies as required.
93
94 It's also possible to call \code{renv::snapshot()} with a non-renv project,
95 in which case it will record the current state of dependencies in the
96 current library paths. This makes it possible to \link{restore} the current packages,
97 providing lightweight portability and reproducibility without isolation.
98
99 If you want to automatically snapshot after each change, you can
100 set \code{config$config$auto.snapshot(TRUE)} -- see \code{?config} for more details.
101 }
102 \section{Snapshot types}{
103 Depending on how you prefer to manage your \R package dependencies, you may
104 want to enable an alternate snapshot type.. The types available are as follows:
105
106 \describe{
107
108 \item{\code{"implicit"}}{
109 (The default) Capture only packages which appear to be used in your project,
110 as determined by \code{renv::dependencies()}. This ensures that only the packages
111 actually required by your project will enter the lockfile; the downside
112 if it might be slow if your project contains a large number of files.
113 If speed becomes an issue, you might consider using \code{.renvignore} files to
114 limit which files renv uses for dependency discovery, or switching to
115 explicit mode, as described next.
116 }
117
118 \item{\code{"explicit"}}{
119 Only capture packages which are explicitly listed in the project
120 \code{DESCRIPTION} file. This workflow is recommended for users who wish to
121 manage their project's \R package dependencies directly, and can be used
122 for both package and non-package \R projects. Packages used in this manner
123 should be recorded in either the \code{Depends} or \code{Imports} field of the
124 \code{DESCRIPTION} file.
125 }
126
127 \item{\code{"all"}}{
128 Capture all packages within the active \R libraries in the lockfile.
129 This is the quickest and simplest method, but may lead to undesired
130 packages (e.g. development dependencies) entering the lockfile.
131 }
132
133 \item{\code{"custom"}}{
134 Like \code{"implicit"}, but use a custom user-defined filter instead. The filter
135 should be specified by the \R option \code{renv.snapshot.filter}, and should
136 either be a character vector naming a function (e.g. \code{"package::method"}),
137 or be a function itself. The function should only accept one argument (the
138 project directory), and should return a vector of package names to include
139 in the lockfile.
140 }
141
142 }
143
144 You can change the snapshot type for the current project with \code{\link[=settings]{settings()}}.
145 For example, the following code will switch to using \code{"explicit"} snapshots:
146
147 \if{html}{\out{<div class="sourceCode">}}\preformatted{renv::settings$snapshot.type("explicit")
148 }\if{html}{\out{</div>}}
149
150 When the \code{packages} argument is set, \code{type} is ignored, and instead only the
151 requested set of packages, and their recursive dependencies, will be written
152 to the lockfile.
153 }
154
155 \examples{
156
157 \dontrun{
158
159 # disable automatic snapshots
160 auto.snapshot <- getOption("renv.config.auto.snapshot")
161 options(renv.config.auto.snapshot = FALSE)
162
163 # initialize a new project (with an empty R library)
164 renv::init(bare = TRUE)
165
166 # install digest 0.6.19
167 renv::install("[email protected]")
168
169 # save library state to lockfile
170 renv::snapshot()
171
172 # remove digest from library
173 renv::remove("digest")
174
175 # check library status
176 renv::status()
177
178 # restore lockfile, thereby reinstalling digest 0.6.19
179 renv::restore()
180
181 # restore automatic snapshots
182 options(renv.config.auto.snapshot = auto.snapshot)
183
184 }
185 }
186 \seealso{
187 More on handling package \code{\link[=dependencies]{dependencies()}}
188
189 Other reproducibility:
190 \code{\link{lockfiles}},
191 \code{\link{restore}()}
192 }
193 \concept{reproducibility}