code_to_plan {drake}R Documentation

Turn an R script file or knitr / R Markdown report into a drake plan. [Questioning]

Description

code_to_plan(), plan_to_code(), and plan_to_notebook() together illustrate the relationships between drake plans, R scripts, and R Markdown documents.

Usage

code_to_plan(path)

Arguments

path

A file path to an R script or knitr report.

Details

This feature is easy to break, so there are some rules for your code file:

  1. Stick to assigning a single expression to a single target at a time. For multi-line commands, please enclose the whole command in curly braces. Conversely, compound assignment is not supported (e.g. target_1 <- target_2 <- target_3 <- get_data()).

  2. Once you assign an expression to a variable, do not modify the variable any more. The target/command binding should be permanent.

  3. Keep it simple. Please use the assignment operators rather than assign() and similar functions.

See Also

drake_plan(), make(), plan_to_code(), plan_to_notebook()

Examples

plan <- drake_plan(
  raw_data = read_excel(file_in("raw_data.xlsx")),
  data = raw_data,
  hist = create_plot(data),
  fit = lm(Ozone ~ Temp + Wind, data)
)
file <- tempfile()
# Turn the plan into an R script a the given file path.
plan_to_code(plan, file)
# Here is what the script looks like.
cat(readLines(file), sep = "\n")
# Convert back to a drake plan.
code_to_plan(file)

[Package drake version 7.13.10 Index]