You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Search for duplicates among the existing issues, both open and closed.
If you think your issue has a quick and definite solution, consider posting to Stack Overflow under the drake-r-package tag. (If you anticipate extended follow-up and discussion, you are already in the right place!)
Description
I want to package my analysis workflow using drake as a research compendium / R package like in this example. This approach (at least so far) involves defining the drake plan in a function. While this worked well with earlier versions of drake, I now run into the following errors/problems:
when using strings in knitr_in() and file_out() in a call to rmarkdown::render(), I get the error:
file_out() files in imported functions are illegal. Detected files: report.md
when instead using variables, I get the warning:
1: Detected knitr_in(!!file_rmd). File paths in file_in(), file_out(), and knitr_in() must be literal strings, not variables. For example, file_in("file1.csv", "file2.csv") is legal, but file_in(paste0(filename_variable, ".csv")) is not. Details: https://books.ropensci.org/drake/plans.html#static-files
2: Detected file_out(!!file_md). File paths in file_in(), file_out(), and knitr_in() must be literal strings, not variables. For example, file_in("file1.csv", "file2.csv") is legal, but file_in(paste0(filename_variable, ".csv")) is not. Details: https://books.ropensci.org/drake/plans.html#static-files
When drake analyzes get_plan() for dependencies, it sees file_out() and knitr_in(), but it does not look for drake_plan() specifically. So it thinks get_plan() just an ordinary function with file_out() and knitr_in() inside. In the general case, file_out() and knitr_in() are not supposed to be inside functions because they cause cycles in the dependency graph.
As a workaround, you can wrap the drake_plan() call inside no_deps() to prevent drake from analyzing it.
library(drake)
get_plan<-function() {
drake_plan(
report=rmarkdown::render(
input= knitr_in("report.Rmd"),
output_file= file_out("report.md"),
output_dir=".",
quiet=TRUE
)
)
}
deps_code(get_plan)
#> Warning: Could not open report.Rmd to detect dependencies.#> Error: file_out() files in imported functions are illegal. Detected files:#> report.mdget_plan<-function() {
no_deps(
drake_plan(
report=rmarkdown::render(
input= knitr_in("report.Rmd"),
output_file= file_out("report.md"),
output_dir=".",
quiet=TRUE
)
)
)
}
deps_code(get_plan)
#> # A tibble: 0 x 2#> # … with 2 variables: name <chr>, type <chr>
Thank you for the explanations, @wlandau-lilly! And thank you for including this as a fix in the latest Github version. Just so I understand a little better—including no_deps() does not alter the within-workflow dependency detection, it's only needed to prevent drake from analyzing get_plan()? So the plan resulting from using the function is identical to defining the plan outside of a function without no_deps()? Thank you!
Yes, you will get the same plan and the same dependency structure in your case. (Unless you call get_plan() inside one of the commands of your targets, which I do not recommend.) But as always, I recommend checking vis_drake_graph() so you are totally confident on the dependency graph.
Prework
drake
's code of conduct.drake-r-package
tag. (If you anticipate extended follow-up and discussion, you are already in the right place!)Description
I want to package my analysis workflow using
drake
as a research compendium / R package like in this example. This approach (at least so far) involves defining thedrake
plan in a function. While this worked well with earlier versions ofdrake
, I now run into the following errors/problems:knitr_in()
andfile_out()
in a call tormarkdown::render()
, I get the error:Reproducible example
Based on
drake
'smtcars
example,Desired result
When defining
my_plan
directly instead of by calling a function, I don't get an error/warning. I expected the same behavior when using a function.Session info
The text was updated successfully, but these errors were encountered: