Define multiple new targets based on existing target objects.

tar_map(values, ..., names = tidyselect::everything(), unlist = FALSE)

Arguments

values

Named list or data frame with values to iterate over. The names are the names of symbols in the commands and pattern statements, and the elements are values that get substituted in place of those symbols. Elements of the values list should be small objects that can easily deparse to names, such as characters, integers, and symbols. For more complicated elements of values, such as lists with multiple numeric vectors, tar_map() attempts to parse the elements into expressions, but this process is not perfect, and the default target names come out garbled. To create a list of symbols as a column of values, use rlang::syms().

...

One or more target objects or list of target objects. Lists can be arbitrarily nested, as in list().

names

Subset of names(values) used to generate the suffixes in the names of the new targets. You can supply symbols, a character vector, or tidyselect helpers like starts_with().

unlist

Logical, whether to flatten the returned list of targets. If unlist = FALSE, the list is nested and sub-lists are named and grouped by the original input targets. If unlist = TRUE, the return value is a flat list of targets named by the new target names.

Value

A list of new target objects. If unlist is FALSE, the list is nested and sub-lists are named and grouped by the original input targets. If unlist = TRUE, the return value is a flat list of targets named by the new target names. See the "Target objects" section for background.

Details

tar_map() creates collections of new targets by iterating over a list of arguments and substituting symbols into commands and pattern statements.

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({ list( tarchetypes::tar_map( list(a = c(12, 34), b = c(45, 78)), targets::tar_target(x, a + b), targets::tar_target(y, x + a, pattern = map(x)) ) ) }) targets::tar_manifest() }) }