@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.