Skip to contents

List the target dependencies of one or more literate programming reports (R Markdown or knitr).

Usage

tar_knitr_deps(path)

Arguments

path

Character vector, path to one or more R Markdown or knitr reports.

Value

Character vector of the names of targets that are dependencies of the knitr report.

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 for tar_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 in tar_load(c(x, y, )), are ignored (superseded syntax and not recommended).

  • Literal character strings inside tidyselect::all_of() and tidyselect::any_of(), e.g. tar_load(all_of(c("x", "y"))). This is the form recommended by the documentation of targets::tar_load(). (Inside all_of() and any_of(), a symbol like all_of(x) refers to the value of a variable x, not a target named x, 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"