I'm trying to knit a plot in two different chunks in RStudio notebook.
Here's a minimal example:
---
title: "R Notebook"
output:
pdf_document: default
html_notebook: default
editor_options:
chunk_output_type: console
---
```{r}
plot(y = 1:61, x = 1:87, type = "n")
```
intermission
```{r}
contour(y = 1:61, x = 1:87, z = volcano, add = TRUE)
```
When running it in RStudio, it fails with the error message of plot.new has not been called yet
when using default settings. Changing chunk output type to console instead of inline fixes it.
However, when knitting, this setting has no effect and it always fails. It is as if the second chunk does not know about the existence of the first chunk.
How to fix it, so it knows to add contour
to the plot
from the first chunk?