It's always great to lead off a report with the key takeaways, for instance a TL:DR header. But it's also great to have a reproducible report where key takeaways are directly linked to your analysis via inline code (E.g., Mean performance was r MY_MEAN).
I'm wondering if there's a smart way to include stats in the TL;DR of an RMarkdown report when the TL;DR necessarily comes before the bulk of the code chunks that would generate its values.
I believe you can use the dependson code chunk option for this. Put your tl;dr code in a chunk with dependson set to a character vector of the (labelled) chunks providing values to be listed.
@joepowers16 you can manage to not have to removed then paste back.
The function knitr::load_cache() handles for you the fact that if the variable is not found it will not error.
Example:
---
title: An important report
output: html_document
---
# TL;DR
* The mean mpg is `r knitr::load_cache("mpg", "my_mean")`
* The median mpg is `r knitr::load_cache("mpg", "my_median")`
# Details
We calculate some stats
```{r mpg, cache=TRUE}
my_mean <- mean(mtcars$mpg)
my_median <- median(mtcars$mpg)
```
First run will show NOT AVAILABLE.
You can recreate this by following the first example in the book chapter using the if clause.
The trick is to print something if the object is not found to not error and render anyway the first time. knitr::load_cache to that for you.