---
title: "Example R Markdown drake file target"
author: Will Landau and Kirill Müller
output: html_document
---

# Content

```{r content}
tryCatch({
  library(drake)
  loadd(fit)
  print(fit)
  readd(hist)
},
error = function(e){
  stop("please read the instructions in the R Markdown file.")
})
```

# Instructions

This file `report.Rmd` belongs to the example from [this chapter of the user manual](https://books.ropensci.org/drake/intro.html) and `drake_example("main")`. The report does not compile from scratch because it is a [file target](https://docs.ropensci.org/drake/reference/file_out.html) in a [`drake`](https://github.com/ropensci/drake)-powered reproducible workflow ([details here](https://books.ropensci.org/drake/plans.html)).

To compile this report,

1. Name it `report.Rmd` (or modify the `knitr_in("report.Rmd")` line in [`make.R`](https://github.com/ropensci/drake/tree/master/inst/rmarkdown/templates/drake/skeleton/make.R) accordingly).
2. Make sure the included file [`raw_data.xlsx`](https://github.com/ropensci/drake/tree/master/inst/rmarkdown/templates/drake/skeleton/raw_data.xlsx) is in your current working directory.
2. Install the [`drake`](https://github.com/ropensci/drake) and [`tidyverse`](https://github.com/tidyverse/tidyverse) packages. 
3. Use [`make.R`](https://github.com/ropensci/drake/tree/master/inst/rmarkdown/templates/drake/skeleton/make.R) (included with this template) to run the [`drake`](https://github.com/ropensci/drake) workflow that compiles this report.

Step 3 not only generates the output file `report.hml`, but also produces a `.drake/` cache in your working directory, which enables `report.Rmd` to compile on its own with with [RStudio](https://www.rstudio.com/products/RStudio/), [`knitr`](https://github.com/yihui/knitr), or [`rmarkdown`](https://github.com/rstudio/rmarkdown). A great way way to generate `report.hml` is still `make(plan)`. That way, compilation happens if and only if there were changes to `report.Rmd`, `report.hml`, `fit`, or `hist` since the last `make()`.
