Prr*_*dep 6 r rstudio knitr r-markdown
是否可以注释掉包含多个块(例如:4-5)的Rmd文件的一部分?常规HTML注释无效。
---
title: "Untitled"
author: "author"
date: "5 August 2017"
output: pdf_document
---
```{r}
print(123)
```
```{r}
2**2
```
<!--
# Comment section starts
This text is not visible in the output.
```{r}
a <- 3*4
a
```
This text not be visible in the output.
# Comment section ends
-->
```{r}
print(1)
```
Run Code Online (Sandbox Code Playgroud)
过去,我记得在SO帖子的某处读到它的目标是下一版knitr。
更新:我并不是要eval=FALSE在每个块中使用该解决方案,因为我也需要注释掉块之间的文本。另外,我正在寻找一种优雅的方式来做到这一点。
上面的代码输出pdf输出,如下所示:
令人惊讶的是,它有效。但是相同的HTML注释(<!-- -->)在另一个原始Rmarkdown脚本中不起作用。仅在包含以下要跳过执行的代码的代码段之后,才实现跳过Rmd文件的一部分。
<!--
# Comment section starts
```{r, include=FALSE}
knitr::opts_chunk$set(eval= FALSE)
```
This is added to the end of the comment:
```{r, include=FALSE, eval=TRUE}
knitr::opts_chunk$set(eval= TRUE)
```
-->
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释这种情况下的问题是什么吗?
我想发布一个更新的答案,因为新版本中的情况已经发生了变化。html 注释<!-- -->现在实现了这一点。因此,html 注释标记之间的所有内容都不会运行或包含在 knitted 文档中。
---
title: "Untitled"
author: "author"
date: "5 August 2017"
output: pdf_document
---
```{r}
print(123)
```
```{r}
2**2
```
<!--
# Comment section starts
This text is not visible in the output.
```{r}
a <- 3*4
a
```
This text not be visible in the output.
# Comment section ends
-->
```{r}
print(1)
```
Run Code Online (Sandbox Code Playgroud)