Use rmarkdown / knitr to keep all the code to the end

I would like to be able to generate a document using knitr / rmarkdown, which combines all the output, but leaves the code to the end, ideally, as a reference footnote (for example, the code for each figure or output can be viewed in the application using a footnote). Is it possible?

+5
source share
1 answer

If I understand correctly, what do you mean. You can add a shortcut to your source code snippet and then access it using the ref.label property and prevent it from further execution using 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 piece is executed (without echo) and shows the figure, the second fragment simply echoes the first source of the fragments.

+6
source

Source: https://habr.com/ru/post/1213151/


All Articles