target {drake}R Documentation

Customize a target in drake_plan(). [Stable]

Description

The target() function is a way to configure individual targets in a drake plan. Its most common use is to invoke static branching and dynamic branching, and it can also set the values of custom columns such as format, elapsed, retries, and max_expand. Details are at ⁠https://books.ropensci.org/drake/plans.html#special-columns⁠. Note: drake_plan(my_target = my_command()) is equivalent to ⁠drake_plan(my_target = target(my_command())⁠.

Usage

target(command = NULL, transform = NULL, dynamic = NULL, ...)

Arguments

command

The command to build the target.

transform

A call to map(), split(), cross(), or combine() to apply a static transformation. Details: ⁠https://books.ropensci.org/drake/static.html⁠

dynamic

A call to map(), cross(), or group() to apply a dynamic transformation. Details: ⁠https://books.ropensci.org/drake/dynamic.html⁠

...

Optional columns of the plan for a given target. See the Columns section of this help file for a selection of special columns that drake understands.

Details

target() must be called inside drake_plan(). It is invalid otherwise.

Value

A one-row workflow plan data frame with the named arguments as columns.

Columns

drake_plan() creates a special data frame. At minimum, that data frame must have columns target and command with the target names and the R code chunks to build them, respectively.

You can add custom columns yourself, either with target() (e.g. drake_plan(y = target(f(x), transform = map(c(1, 2)), format = "fst"))) or by appending columns post-hoc (e.g. plan$col <- vals).

Some of these custom columns are special. They are optional, but drake looks for them at various points in the workflow.

Keywords

drake_plan() understands special keyword functions for your commands. With the exception of target(), each one is a proper function with its own help file.

Formats

Specialized target formats increase efficiency and flexibility. Some allow you to save specialized objects like keras models, while others increase the speed while conserving storage and memory. You can declare target-specific formats in the plan (e.g. drake_plan(x = target(big_data_frame, format = "fst"))) or supply a global default format for all targets in make(). Either way, most formats have specialized installation requirements (e.g. R packages) that are not installed with drake by default. You will need to install them separately yourself. Available formats:

See Also

drake_plan(), make()

Examples

# Use target() to create your own custom columns in a drake plan.
# See ?triggers for more on triggers.
drake_plan(
  website_data = target(
    download_data("www.your_url.com"),
    trigger = "always",
    custom_column = 5
  ),
  analysis = analyze(website_data)
)
models <- c("glm", "hierarchical")
plan <- drake_plan(
  data = target(
    get_data(x),
    transform = map(x = c("simulated", "survey"))
  ),
  analysis = target(
    analyze_data(data, model),
    transform = cross(data, model = !!models, .id = c(x, model))
  ),
  summary = target(
    summarize_analysis(analysis),
    transform = map(analysis, .id = c(x, model))
  ),
  results = target(
    bind_rows(summary),
    transform = combine(summary, .by = data)
  )
)
plan
if (requireNamespace("styler", quietly = TRUE)) {
  print(drake_plan_source(plan))
}

[Package drake version 7.13.9 Index]