transformations: Transformations in 'drake_plan()'. *[Stable]*

transformationsR Documentation

Transformations in drake_plan(). [Stable]


In drake_plan(), you can define whole batches of targets with transformations such as map(), split(), cross(), and combine().



Grouping variables. New grouping variables must be supplied with their names and values, existing grouping variables can be given as symbols without any values assigned. For dynamic branching, the entries in ... must be unnamed symbols with no values supplied, and they must be the names of targets.


A data frame of new grouping variables with grouping variable names as column names and values as elements.


Literal character vector of names for the targets. Must be the same length as the targets generated.


Symbol or vector of symbols naming grouping variables to incorporate into target names. Useful for creating short target names. Set .id = FALSE to use integer indices as target name suffixes.


A symbol or vector of symbols. Tags assign targets to grouping variables. Use .tag_in to assign untransformed targets to grouping variables.


Just like .tag_in, except that .tag_out assigns transformed targets to grouping variables.


Number of slices into which split() partitions the data.


Which margin to take the slices in split(). Same meaning as the MARGIN argument of apply().


Logical, whether to drop a dimension if its length is 1. Same meaning as mtcars[, 1L, drop = TRUE] versus mtcars[, 1L, drop = TRUE].


Symbol or vector of symbols of grouping variables. combine() aggregates/groups targets by the grouping variables in .by. For dynamic branching, .by can only take one variable at a time, and that variable must be a vector. Ideally, it should take little space in memory.


Symbol or vector of symbols for the dynamic trace. The dynamic trace allows you to keep track of the values of dynamic dependencies are associated with individual sub-targets. For combine(), .trace must either be empty or the same as the variable given for .by. See get_trace() and read_trace() for examples and other details.


For details, see


drake has special syntax for generating large plans. Your code will look something like drake_plan(y = target(f(x), transform = map(x = c(1, 2, 3))) You can read about this interface at # nolint

Static branching

In static branching, you define batches of targets based on information you know in advance. Overall usage looks like drake_plan(<x> = target(<...>, transform = <call>), where

  • <x> is the name of the target or group of targets.

  • <...> is optional arguments to target().

  • <call> is a call to one of the transformation functions.

Transformation function usage:

  • map(..., .data, .names, .id, .tag_in, .tag_out)

  • split(..., slices, margin = 1L, drop = FALSE, .names, .tag_in, .tag_out) # nolint

  • cross(..., .data, .names, .id, .tag_in, .tag_out)

  • combine(..., .by, .names, .id, .tag_in, .tag_out)

Dynamic branching

  • map(..., .trace)

  • cross(..., .trace)

  • group(..., .by, .trace)

map() and cross() create dynamic sub-targets from the variables supplied to the dots. As with static branching, the variables supplied to map() must all have equal length. group(f(data), .by = x) makes new dynamic sub-targets from data. Here, data can be either static or dynamic. If data is dynamic, group() aggregates existing sub-targets. If data is static, group() splits data into multiple subsets based on the groupings from .by.

Differences from static branching:

  • ... must contain unnamed symbols with no values supplied, and they must be the names of targets.

  • Arguments .id, .tag_in, and .tag_out no longer apply.


# Static branching
models <- c("glm", "hierarchical")
plan <- drake_plan(
  data = target(
    transform = map(x = c("simulated", "survey"))
  analysis = target(
    analyze_data(data, model),
    transform = cross(data, model = !!models, .id = c(x, model))
  summary = target(
    transform = map(analysis, .id = c(x, model))
  results = target(
    transform = combine(summary, .by = data)
if (requireNamespace("styler")) {
# Static splitting
plan <- drake_plan(
  analysis = target(
    transform = split(data, slices = 3L, margin = 1L, drop = FALSE)
if (requireNamespace("styler", quietly = TRUE)) {
# Static tags:
  x = target(
    transform = map(y = c(1, 2), .tag_in = from, .tag_out = c(to, out))
  trace = TRUE
plan <- drake_plan(
  survey = target(
    transform = map(x = c(1, 2), .tag_in = source, .tag_out = dataset)
  download = target(
    transform = map(y = c(5, 6), .tag_in = source, .tag_out = dataset)
  analysis = target(
    transform = map(dataset)
  results = target(
    transform = combine(analysis, .by = source)
if (requireNamespace("styler", quietly = TRUE)) {

drake documentation built on Aug. 19, 2022, 5:21 p.m.