Use rmarkdown/knitr to hold all code until the end
One solution is add this chunk at the end.
{r ref.label=knitr::all_labels(), echo=TRUE, eval=FALSE}
Then you will have all the code together whitout evaluation.
If I understand correctly what you mean.
You can add a label to your original code chunk and then refer to it using a ref.label
property and prevent its further execution with eval=FALSE
.
For instance:
# Header
Bla bla ...
````{r plot1,echo=FALSE}
x = rnorm(100,10,5)
y = rnorm(100,10,5)
plot(x,y)
````
# Appendix
Code chunk:
````{r ref.label="plot1",eval=FALSE}
```
The first chunk is executed (without echo) and shows a figure, the second chunk just echoes the first chunk's source.