Use rmarkdown/knitr to hold all code until the end

℡╲_俬逩灬. 提交于 2019-12-07 00:13:58

问题


I'd like to be able to generate a document using knitr/rmarkdown that keeps all the output together, but leaves the code until the end, ideally as a referenced footnote of sorts (i.e. the code for each figure or output can be looked up in the appendix using a footnote). Is this possible?


回答1:


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.



来源:https://stackoverflow.com/questions/28458384/use-rmarkdown-knitr-to-hold-all-code-until-the-end

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!