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))))
}

Try the tarchetypes package in your browser

Any scripts or data that you put into this service are public.

tarchetypes documentation built on Oct. 4, 2023, 5:08 p.m.