List the target dependencies of one or more
literate programming reports (R Markdown or knitr).
Literate programming dependencies
Upstream target dependencies of a report are detected by
static code analysis of the active code chunks
before the pipeline runs.
The analysis looks for calls to tar_load() and tar_read()
(with or without the targets:: prefix) and reads
the names argument of tar_load() and the name argument
of tar_read(). Because target names must be known in advance,
only the following forms are detected:
Symbols, e.g.
tar_read(x)(recommended fortar_read()).Character strings, e.g.
tar_read("x")(superseded syntax).Combinations of the above with
c(), e.g.tar_load(c(x, "y")). Empty arguments from trailing commas, as intar_load(c(x, y, )), are ignored (superseded syntax and not recommended).Literal character strings inside
tidyselect::all_of()andtidyselect::any_of(), e.g.tar_load(all_of(c("x", "y"))). This is the form recommended by the documentation oftargets::tar_load(). (Insideall_of()andany_of(), a symbol likeall_of(x)refers to the value of a variablex, not a target namedx, so it is not detected and a warning is thrown.)
Other tidyselect selectors such as starts_with(), ends_with(),
contains(), matches(), num_range(), last_col(),
and everything() cannot be resolved in advance,
so they throw a warning and contribute no dependencies.
tar_load_raw() and tar_read_raw() are not detected at all.
To check which dependencies are detected in a report,
use tar_knitr_deps().
See also
Other Literate programming utilities:
tar_knitr_deps_expr(),
tar_quarto_files()
Examples
lines <- c(
"---",
"title: report",
"output_format: html_document",
"---",
"",
"```{r}",
"targets::tar_load(data1)",
"targets::tar_read(data2)",
"```"
)
report <- tempfile()
writeLines(lines, report)
tar_knitr_deps(report)
#> [1] "data1" "data2"