4

When using Stangle on a Sweave document, the output includes a comment that gives the chunk name. 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):

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.

Is there a way to force knitr to produce comments in tangled R code that include chunk names (and/or numbers) like native Stangle?

4

1 回答 1

5

感谢@kohske(我刚刚自己想通了……)

purl()有一个documentation参数,默认设置为 1(1=将块头添加到代码中;0 什么都不做,2 添加块头作为 roxygen 注释)。如果你想坚持knit(.,tangle=TRUE)你只需要opts_knit$set(documentation=1)在纠结之前。

于 2014-01-25T19:10:12.187 回答