Example knir report in a targets pipeline

library(targets)
knitr::opts_chunk$set(echo = TRUE)

This R Markdown report depends on targets from a targets pipeline. Declare these dependencies with tar_load() and tar_read().

tar_load(data)
plot(tar_read(analysis))

You can include this report itself as a target. Simply use the tar_render() archetype to define the target, which tells targets to automatically find dependnecies like data and analysis and rerun the report when either dependency changes.

The code analysis tries to be intelligent, so tar_load() and tar_read() can appear in various places.

f <- function() {
  targets::tar_read(name = data2)
}

However, the dependencies are always detected using static code analysis, which means tidyselect syntax like tar_load(starts_with("data")) will not work. targets requires you to write the literal symbol name of every target you want the report to depend on.

tar_load(names = c("string1", "string2"))
tar_read(name = "string3")
not
a
target


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.