【发布时间】:2016-06-21 17:12:57
【问题描述】:
出于教学目的,我想将purl 我的.Rnw 文件的块分成单独的文件。这个答案解释了如何做到这一点:
How to purl each chunks in .Rmd file to multiple .R files using Knitr
但是该方法不保留块选项。由于我已经生成了块,因此保留 fig.width 和 fig.height 选项很重要。理想情况下,我想要一个如下所示的块:
<<plot, fig.width = 3, fig.height = 5, outwidth = '.75\\textwidth'>>=
plot (1,1)
@
变成一个名为plot.R 的文件,如下所示:
#+ fig.width = 3, fig.height = 5
plot (1,1)
也就是说,将块选项fig.width和fig.height转换为spin()可以识别的格式,就像purl()所做的那样,去掉不相关的块选项,或者为spin() 转入 Word,如 out.width。一切都本着创建用户友好的代码文件的精神。
【问题讨论】: