RMarkdown 代码评估直到命令

RMarkdown code evaluation until command

我在构建分析时使用 RMarkdown。最终输出将是一个 html 文档。实际上我有一个核心代码,这将是最终文档,在结束之后,我有很多代码行,其中包含 目前 没有用的块和句子,但可以包含在最终文件中。

不仅像 eval=FALSE 用于块(我也有纯文本),而且像 TeX 中的 \end{document}。我不想只评论纯文本并将 eval=FALSE 作为块选项。

我尝试 google 并阅读了 RMarkdown 文档,但我一无所获。

谢谢大家!请原谅我糟糕的英语...

我找不到在两种文档类型中获取此信息的方法。因此,如果您想创建 PDF,请使用第一个示例,不要使用 <!-- -->。在 HTML 中,您可以在文档中保留两个注释字符。

这个 PDF 怎么样

title: "Untitled"
author: "Mario Dejung <m.dejung@imb.de>"
date: "28 Sep 2016"
output: pdf_document
header-includes: \usepackage{comment}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

\begin{comment}

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

\end{comment}

这是 HTML

---
title: "Untitled"
author: "Mario Dejung <m.dejung@imb.de>"
date: "28 Sep 2016"
output: html_document
header-includes: \usepackage{comment}
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r cars}
summary(cars)
```

<!--

\begin{comment}

## Including Plots

You can also embed plots, for example:

```{r pressure, echo=FALSE}
plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

\end{comment}

-->

来自 knit_exit() 的文档:

Sometimes we may want to exit the knitting process early, and completely ignore the rest of the document. This function provides a mechanism to terminate knit().

示例:

Text.

```{r}
print(1)
```

More text.

```{r}
knitr::knit_exit()
```

Ignored.

```{r}
print("Ignored.")
```

knit_exit() 之后的所有内容都将被忽略。这适用于所有输出格式。

上面的代码产生: