[英]missing chunk names in knitr tangled R code
When using Stangle
on a Sweave
document, the output includes a comment that gives the chunk name. 在
Sweave
文档上使用Stangle
时,输出包含一个给出块名称的注释。 This is incredibly useful in a teaching setting to orient students in the code as they cut-and-paste. 这在教学环境中非常有用,可以让学生在剪切和粘贴时对代码进行定位。 However, when I use
knitr
to generate the .R
code from a .Rnw
, the chunk names are not included (at least that I can see): 但是,当我使用
knitr
从.Rnw
生成.R
代码时,不包括块名称(至少我可以看到):
knit('example.Rnw',tangle=TRUE)
I could run Stangle
on a document written for knitr
except that there are incompatibilities in chunk arguments that preclude running Stangle
without errors. 我可以在为
knitr
编写的文档上运行Stangle
,除了块参数中存在不兼容性以阻止运行Stangle
而没有错误。
Is there a way to force knitr
to produce comments in tangled R
code that include chunk names (and/or numbers) like native Stangle
? 有没有办法强制
knitr
在纠结的R
代码中产生注释,包括像本机Stangle
一样的块名(和/或数字)?
Thanks to @kohske (I had just about figured this out for myself ...) 感谢@kohske(我刚刚为自己想出了这个......)
purl()
has a documentation
argument, which is set to 1 by default (1=add chunk headers to code; 0 does nothing, 2 adds chunk headers as roxygen comments). purl()
有一个documentation
参数,默认设置为1(1 =将chunk头添加到代码中; 0不执行任何操作,2添加块头作为roxygen注释)。 If you want to stick to knit(.,tangle=TRUE)
you just need to opts_knit$set(documentation=1)
before tangling. 如果你想坚持
knit(.,tangle=TRUE)
opts_knit$set(documentation=1)
knit(.,tangle=TRUE)
你只需要在纠缠之前选择opts_knit$set(documentation=1)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.