R/dependencies.R
Intended for debugging and checking your project. The dependency structure of the components of your analysis decides which targets are built and when.
deps(x)
x | Either a function or a string. Strings are commands from your workflow plan data frame. |
---|
A character vector, names of dependencies. Files wrapped in single quotes. The other names listed are functions or generic R objects.
If the argument is a double-quoted string that points to
a dynamic knitr report, the dependencies of the expected compiled
output will be given. For example, deps(file_store("report.Rmd"))
will return target names found in calls to loadd()
and readd()
in active code chunks. The file_store()
function
(alerts drake
utility functions to file names by double-quoting them.)
These loadd()
/readd()
targets are needed
in order to run knit(knitr_in("report.Rmd"))
to produce the output file "report.md"
, so technically,
they are dependencies of "report.md"
, not "report.Rmd"
.
Drake
takes special precautions so that a target/import
does not depend on itself. For example, deps(f)`` might return
"f"if
f()` is a recursive function, but make()
just ignores
this conflict and runs as expected. In other words, make()
automatically removes all self-referential loops in the dependency
network.
# Your workflow likely depends on functions in your workspace. f <- function(x, y){ out <- x + y + g(x) saveRDS(out, 'out.rds') } # Find the dependencies of f. These could be R objects/functions # in your workspace or packages. Any file names or target names # will be ignored. deps(f)#> [1] "g" "saveRDS"# Define a workflow plan data frame that uses your function f(). my_plan <- drake_plan( x = 1 + some_object, my_target = x + readRDS(file_in("tracked_input_file.rds")), return_value = f(x, y, g(z + w)), strings_in_dots = "literals" ) # Get the dependencies of workflow plan commands. # Here, the dependencies could be R functions/objects from your workspace # or packages, imported files, or other targets in the workflow plan. deps(my_plan$command[1])#> [1] "some_object"deps(my_plan$command[2])#> [1] "readRDS" "\"tracked_input_file.rds\"" #> [3] "x"deps(my_plan$command[3])#> [1] "f" "g" "w" "x" "y" "z"# NOT RUN { test_with_dir("Quarantine side effects.", { load_basic_example() # Get the code with drake_example("basic"). # Dependencies of the knitr-generated targets like 'report.md' # include targets/imports referenced with `readd()` or `loadd()`. deps(file_store("report.Rmd")) }) # }