---
title: "Example knir report in a targets pipeline"
output: html_document
---

```{r setup, include=FALSE}
library(targets)
knitr::opts_chunk$set(echo = TRUE)
```

This R Markdown report depends on targets from a [`targets`](https://github.com/ropensci/targets) pipeline. Declare these dependencies with `tar_load()` and `tar_read()`.

```{r}
tar_load(data)
```

```{r}
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.

```{r}
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.

```{r}
tar_load(names = c("string1", "string2"))
```

```{r}
tar_read(name = "string3")
```

```{r}
not
a
target
```
