renv
Write package dependencies to a script file
(by default, named _packages.R
in the root project directory).
Each package is written to a separate line
as a standard library()
call (e.g. library(package)
) so
renv
can identify them automatically. This is only
necessary if the user invokes tar_option_set()
or tar_target()
to
declare packages rather than the usual library()
or namespaced call
(i.e. package::function()
). See Details
for more information.
tar_renv(
packages = targets::tar_option_get("packages"),
path = "_packages.R",
ask = NULL
)
Character vector of packages to load right before
the target builds. Use tar_option_set()
to set packages
globally for all subsequent targets you define.
Character of length 1, path to the script file to
populate with library()
calls.
Logical, whether to ask before writing if _packages.R
already exists. If NULL
, defaults to Sys.getenv("TAR_ASK")
.
(Set to "true"
or "false"
with Sys.setenv()
).
If ask
and the TAR_ASK
environment variable are both
indeterminate, defaults to interactive()
.
Nothing, invisibly.
This function gets called for its side-effect, which writes
package dependencies provided to the packages
argument to
a script. If you do not explicitly set the packages
argument,
tar_renv()
will only detect the packages that
tar_option_get("packages")
returns at that point in the code.
The generated file should not be edited by hand and will be
overwritten each time tar_renv()
runs non-interactively.
With the script written by tar_renv()
, renv
is able to crawl the
file to identify package dependencies (with renv::dependencies()
).
Calling renv::init()
after tar_renv()
has ran will set up a
project-local R
library. This allows your targets
pipeline to have
its own self-contained R
library separate from your standard R
library. See https://rstudio.github.io/renv/index.html for
more information.
# NOT RUN {
tar_dir({
tar_option_set(packages = c("tibble", "qs"))
tar_renv()
readLines("_packages.R")
})
# }
Run the code above in your browser using DataLab