code_to_plan {drake} | R Documentation |
Turn an R script file or knitr
/ R Markdown report
into a drake
plan.
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 |
Details
This feature is easy to break, so there are some rules for your code file:
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()
).Once you assign an expression to a variable, do not modify the variable any more. The target/command binding should be permanent.
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)