knitr中的R针对看起来像块标签的注释感到困惑

use*_*743 3 r knitr

我正在使用R中knitr包中的stitch函数为我的学生创建R代码的html文件.

我有几百个R脚本,并且自动创建html页面的过程.

但是,如果我的R脚本包含注释行,例如

## ------示例------

然后是针脚功能thinks这是代码块的标签,并经常删除我脚本的其他部分.

有没有办法在函数turn off 中分块stitch()来传递所有代码as is?我已经查看了内部代码,stitch()并且read_chunk()似乎无法看到它## ----- Example -----是如何知道何时 是块标签.

这是最小的工作示例:R 3.0.1; knitr 1.4.1

# Test out problem with stitch in knitr

my.code <- "# This a sample of R code
x <- 1:10
print(x)
plot(x,x)

## ---------------- Example  -----
# Notice that only this part of the code appears in the html file.
x <- 10:30
print(x)
plot(x,x)

NULL
"

writeLines(my.code, con='R.code')

library(knitr)
stitch("R.code", system.file("misc", "knitr-template.Rhtml", package = "knitr"))
Run Code Online (Sandbox Code Playgroud)

Yih*_*Xie 5

这是knitr 1.3中引入的一个新功能:# ----在使用时将被视为块头的标记read_chunk().

如果您不想要此功能,则可以使用少于4个短划线#,例如

## --- Example ----
## -- Example ----
## Example ----
Run Code Online (Sandbox Code Playgroud)

我假设你有这样的评论,为了RStudio代码部分,这需要在部分标题的末尾至少有四个破折号.

然后你需要Github上的开发版knitr v1.4.6来完全解决这个问题.