R/tar_knitr_deps.R

Defines functions tar_knitr_deps

Documented in tar_knitr_deps

#' @title List literate programming dependencies.
#' @export
#' @family Literate programming utilities
#' @description List the target dependencies of one or more
#'   literate programming reports (R Markdown or `knitr`).
#' @return Character vector of the names of targets
#'   that are dependencies of the `knitr` report.
#' @param path Character vector, path to one or more R Markdown or
#'   `knitr` reports.
#' @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)
tar_knitr_deps <- function(path) {
  targets::tar_assert_path(path)
  targets::tar_assert_not_dirs(path)
  sort(unique(unlist(map(path, knitr_deps))))
}
wlandau/tarchetypes documentation built on Sept. 26, 2024, 12:23 p.m.