Debian Codegraph @

man/embed.Rd

raw
1 % Generated by roxygen2: do not edit by hand
2 % Please edit documentation in R/embed.R, R/use.R
3 \name{embed}
4 \alias{embed}
5 \alias{use}
6 \title{Capture and re-use dependencies within a \code{.R}, \code{.Rmd} or \code{.qmd}}
7 \usage{
8 embed(path = NULL, ..., lockfile = NULL, project = NULL)
9
10 use(
11 ...,
12 lockfile = NULL,
13 library = NULL,
14 repos = getOption("repos"),
15 isolate = TRUE,
16 sandbox = TRUE,
17 attach = FALSE,
18 verbose = TRUE
19 )
20 }
21 \arguments{
22 \item{path}{The path to an \R or R Markdown script. The default will use the current
23 document, if running within RStudio.
24 \subsection{Package Resolution}{
25
26 When \code{embed()} generates a call to \code{use()}, it needs to determine the
27 package versions to record. The \code{lockfile} parameter controls where these
28 versions come from:
29 \enumerate{
30 \item If \code{lockfile} is \code{NULL} (the default), and the project has an existing
31 \code{renv.lock} file, that project lockfile is used. Only packages present
32 in the lockfile will be included -- any dependencies not recorded in the
33 lockfile will be omitted.
34 \item If \code{lockfile} is a path to a lockfile, or a lockfile object, that
35 lockfile is used directly.
36 \item If \code{lockfile} is \code{FALSE}, or if no project lockfile exists, package
37 versions are inferred from the currently-installed packages in the
38 active library paths.
39 \item If \code{lockfile} is \code{NA}, package versions are inferred from the
40 latest versions available in the active package repositories.
41 }
42 }}
43
44 \item{...}{The \R packages to be used with this script. Ignored if \code{lockfile} is
45 non-\code{NULL}.}
46
47 \item{lockfile}{The lockfile to use. When supplied, renv will use the packages as
48 declared in the lockfile.}
49
50 \item{project}{The project directory. If \code{NULL}, then the active project will
51 be used. If no project is currently active, then the current working
52 directory is used instead.}
53
54 \item{library}{The library path into which the requested packages should be installed.
55 When \code{NULL} (the default), a library path within the \R temporary
56 directory will be generated and used. Note that this same library path
57 will be re-used on future calls to \code{renv::use()}, allowing \code{renv::use()}
58 to be used multiple times within a single script.}
59
60 \item{repos}{The \R package repositories to use. When \code{NULL}, packages will be
61 resolved from the renv cache, without querying any external repositories.
62 This can be useful if you'd like to use packages that have already been
63 cached by renv, even when no active package repositories have been
64 configured.}
65
66 \item{isolate}{Boolean; should the active library paths be included in the set of library
67 paths activated for this script? Set this to \code{TRUE} if you only want the
68 packages provided to \code{renv::use()} to be visible on the library paths.}
69
70 \item{sandbox}{Should the system library be sandboxed? See the sandbox documentation in
71 \link{config} for more details. You can also provide an explicit sandbox
72 path if you want to configure where \code{renv::use()} generates its sandbox.
73 By default, the sandbox is generated within the \R temporary directory.}
74
75 \item{attach}{Boolean; should the set of requested packages be automatically attached?
76 If \code{TRUE}, packages will be loaded and attached via a call
77 to \code{\link[=library]{library()}} after install. Ignored if \code{lockfile} is non-\code{NULL}.}
78
79 \item{verbose}{Boolean; be verbose while installing packages?}
80 }
81 \value{
82 This function is normally called for its side effects.
83 }
84 \description{
85 Together, \code{embed()} and \code{use()} provide a lightweight way to specify and
86 restore package versions within a file. \code{use()} is a lightweight lockfile
87 specification that \code{embed()} can automatically generate and insert into a
88 script or document.
89
90 Calling \code{embed()} inspects the dependencies of the specified document then
91 generates and inserts a call to \code{use()} that looks something like this:
92
93 \if{html}{\out{<div class="sourceCode R">}}\preformatted{renv::use(
94 "[email protected]",
95 "[email protected]"
96 )
97 }\if{html}{\out{</div>}}
98
99 When you next run your R script or render your \code{.Rmd} or \code{.qmd}, \code{use()} will:
100 \enumerate{
101 \item Create a temporary library path,
102 \item Install the requested packages and their recursive dependencies into that
103 library,
104 \item Activate the library, so it's used for the rest of the script.
105 }
106 \subsection{Manual usage}{
107
108 You can also create calls to \code{use()} yourself, either specifying the
109 packages needed by hand, or by supplying the path to a lockfile,
110 \code{renv::use(lockfile = "/path/to/renv.lock")}.
111
112 This can be useful in projects where you'd like to associate different
113 lockfiles with different documents, as in a blog where you want each
114 post to capture the dependencies at the time of writing. Once you've
115 finished writing each, the post, you can use
116 \code{renv::snapshot(lockfile = "/path/to/renv.lock")}
117 to "save" the state that was active while authoring that bost, and then use
118 \code{renv::use(lockfile = "/path/to/renv.lock")} in that document to ensure the
119 blog post always uses those dependencies onfuture renders.
120
121 \code{renv::use()} is inspired in part by the \href{https://groundhogr.com/}{groundhog}
122 package, which also allows one to specify a script's \R package requirements
123 within that same \R script.
124 }
125 }