drake (version 7.3.0)

map_plan: Deprecated: create a plan that maps a function to a grid of arguments.

Description

Deprecated on 2019-05-16. Use drake_plan() transformations instead. See https://ropenscilabs.github.io/drake-manual/plans.html#large-plans for the details.

Usage

map_plan(args, fun, id = "id", character_only = FALSE, trace = FALSE)

Arguments

args

A data frame (or better yet, a tibble) of function arguments to fun. Here, the column names should be the names of the arguments of fun, and each row of args corresponds to a call to fun.

fun

Name of a function to apply the arguments row-by-row. Supply a symbol if character_only is FALSE and a character scalar otherwise.

id

Name of an optional column in args giving the names of the targets. If not supplied, target names will be generated automatically. id should be a symbol if character_only is FALSE and a character scalar otherwise.

character_only

Logical, whether to interpret the fun and id arguments as character scalars or symbols.

trace

Logical, whether to append the columns of args to the output workflow plan data frame. The added columns help "trace back" the original settings that went into building each target. Similar to the trace argument of drake_plan().

Value

A workflow plan data frame.

Details

map_plan() is like base::Map(): it takes a function name and a grid of arguments, and writes out all the commands calls to apply the function to each row of arguments.

See Also

drake_plan()

Examples

Run this code
# NOT RUN {
suppressWarnings({
# For the full tutorial, visit
# https://ropenscilabs.github.io/drake-manual/plans.html#map_plan.
my_model_fit <- function(x1, x2, data) {
  lm(as.formula(paste("mpg ~", x1, "+", x1)), data = data)
}
covariates <- setdiff(colnames(mtcars), "mpg")
args <- t(combn(covariates, 2))
colnames(args) <- c("x1", "x2")
# Use tibble::as_tibble(args) for better printing # nolint
# Below, stringsAsFactors = FALSE is very important! # nolint
args <- as.data.frame(args, stringsAsFactors = FALSE)
args$data <- "mtcars"
args$data <- rlang::syms(args$data)
args$id <- paste0("fit_", args$x1, "_", args$x2)
# print(args) # Requires `args` to be a tibble # nolint
plan <- map_plan(args, my_model_fit)
plan
# Consider `trace = TRUE` to include the columns in `args`
# in your plan.
plan <- map_plan(args, my_model_fit, trace = TRUE)
# print(plan) # If you have tibble installed # nolint
# And of course, you can execute the plan and
# inspect your results.
cache <- storr::storr_environment()
make(plan, verbose = FALSE, cache = cache)
readd(fit_cyl_disp, cache = cache)
})
# }

Run the code above in your browser using DataLab