tar_map: Static branching.

View source: R/tar_map.R

tar_mapR Documentation

Static branching.

Description

Define multiple new targets based on existing target objects.

Usage

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. tar_map() uses these elements to create new R code, so they should be basic types, symbols, or R expressions. For objects even a little bit complicated, especially objects with attributes, it is not obvious how to convert the object into code that generates it. For complicated objects, consider using quote() when you define values, as shown at https://github.com/ropensci/tarchetypes/discussions/105.

...

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.

Details

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

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.

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

Other branching: tar_combine_raw(), tar_combine(), tar_map2_count_raw(), tar_map2_count(), tar_map2_raw(), tar_map2_size_raw(), tar_map2_size(), tar_map2(), tar_map_rep_raw(), tar_map_rep(), tar_rep2_raw(), tar_rep2(), tar_rep_map_raw(), tar_rep_map(), tar_rep_raw(), tar_rep()

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()
})
}

tarchetypes documentation built on Dec. 1, 2022, 1:31 a.m.