使用rmarkdown/knitr将所有代码保留到最后 [英] Use rmarkdown/knitr to hold all code until the end

查看:192
本文介绍了使用rmarkdown/knitr将所有代码保留到最后的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够使用knitr/rmarkdown生成一个文档,该文档将所有输出保持在一起,但是将代码保留到最后,理想情况下是作为各种类型的引用脚注(即,每个图形或输出的代码可以可以在脚注中在附录中查找).这可能吗?

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?

推荐答案

如果我正确理解您的意思. 您可以在原始代码块中添加标签,然后使用ref.label属性引用它,并使用eval=FALSE阻止其进一步执行.

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.

例如:

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

这篇关于使用rmarkdown/knitr将所有代码保留到最后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆