View source: R/tar_hook_before.R
tar_hook_before | R Documentation |
Prepend R code to the commands of multiple targets.
tar_hook_before()
expects unevaluated expressions for the hook
and
names
arguments, whereas tar_hook_before_raw()
expects
evaluated expression objects.
tar_hook_before(
targets,
hook,
names = NULL,
set_deps = TRUE,
envir = parent.frame()
)
tar_hook_before_raw(
targets,
hook,
names = NULL,
set_deps = TRUE,
envir = parent.frame()
)
targets |
A list of target objects. The input target list can be arbitrarily nested, but it must consist entirely of target objects. In addition, the return value is a simple list where each element is a target object. All hook functions remove the nested structure of the input target list. |
hook |
R code to insert.
|
names |
Name of targets in the target list
to apply the hook. Supplied using The regular hook functions expects unevaluated expressions for the |
set_deps |
Logical of length 1, whether to refresh the dependencies
of each modified target by scanning the newly generated
target commands for dependencies. If |
envir |
Optional environment to construct the quosure for the |
A flattened list of target objects with the hooks applied. Even if the input target list had a nested structure, the return value is a simple list where each element is a target object. All hook functions remove the nested structure of the input target list.
Most tarchetypes
functions are target factories,
which means they return target objects
or lists of target objects.
Target objects represent skippable steps of the analysis pipeline
as described at https://books.ropensci.org/targets/.
Please read the walkthrough at
https://books.ropensci.org/targets/walkthrough.html
to understand the role of target objects in analysis pipelines.
For developers, https://wlandau.github.io/targetopia/contributing.html#target-factories explains target factories (functions like this one which generate targets) and the design specification at https://books.ropensci.org/targets-design/ details the structure and composition of target objects.
Other hooks:
tar_hook_inner()
,
tar_hook_outer()
if (identical(Sys.getenv("TAR_LONG_EXAMPLES"), "true")) {
targets::tar_dir({ # tar_dir() runs code from a temporary directory.
targets::tar_script({
targets <- list(
# Nested target lists work with hooks.
list(
targets::tar_target(x1, task1()),
targets::tar_target(x2, task2(x1))
),
targets::tar_target(x3, task3(x2)),
targets::tar_target(y1, task4(x3))
)
tarchetypes::tar_hook_before(
targets = targets,
hook = print("Running hook."),
names = starts_with("x")
)
})
targets::tar_manifest(fields = command)
})
# With tar_hook_before_raw():
targets::tar_script({
targets <- list(
# Nested target lists work with hooks.
list(
targets::tar_target(x1, task1()),
targets::tar_target(x2, task2(x1))
),
targets::tar_target(x3, task3(x2)),
targets::tar_target(y1, task4(x3))
)
tarchetypes::tar_hook_before_raw(
targets = targets,
hook = quote(print("Running hook.")),
names = quote(starts_with("x"))
)
})
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.