Wrap the command of each target in an arbitrary R expression.

tar_hook_outer(targets, hook, names = NULL)

Arguments

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 wrap each target's command. The hook must contain the special placeholder symbol .x so tar_hook_outer() knows where to insert the original command of the target. The hook code is quoted (not evaluated) so there is no need to wrap it in quote(), expression(), or similar.

names

Name of targets in the target list to apply the hook. You can supply symbols, a character vector, or tidyselect helpers like starts_with(). Targets not included in names still remain in the target list, but they are not modified because the hook does not apply to them.

Value

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.

Details

The expression you supply to hook must contain the special placeholder symbol .x so tar_hook_outer() knows where to insert the original command of the target.

Target objects

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.

See also

Examples

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_outer( targets = targets, hook = postprocess(.x, arg = "value"), names = starts_with("x") ) }) targets::tar_manifest(fields = command) }) }