2016-09-28 131 views
3

我正在使用RMarkdown我在建立我的分析。最终的输出将是一个html文档。其实我有一个核心代码,这将是最后的文件,并在结束后,我有很多代码块和句子目前没有用,但可以包含在最终文件。RMarkdown代码评估,直到命令

    是否存在一条命令用于说明RMarkdown在此之前评估代码?

不一样eval=FALSE的块(我也得到了纯文本),但在的TeX\end{document}。我不想仅仅评论纯文本,并把eval=FALSE作为块选项。

我试图谷歌和阅读RMarkdown文件,但我什么也没找到。

谢谢大家!并原谅我为我可怜的英语...

+0

你可以使用'knitr :: opts_chunk $组(EVAL = FALSE)'设置EVAL = FALSE的命令后所有块;我不知道如何轻松地为文本做到这一点。 – scoa

+0

感谢@scoa。我知道'chunk $ set'的使用,实际上我使用它来不评估不需要的代码并节省时间。 –

+0

不是什么玩具要求,但因为它仍然评估文本,但不显示它在HTML中使用HTML评论'' –

回答

4

knit_exit()文档:

有时我们可能需要提前退出针织过程中,并完全忽略文档的其余部分。此功能提供了一种机制来终止knit()

例子:

一切后 knit_exit()
Text. 

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

More text. 

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

Ignored. 

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

将被忽略。这适用于所有输出格式。

上面的代码产生:

enter image description here

+0

@SimoneMarini不用担心,乐于帮忙! –

0

我找不到一种方式来获得这两种文件类型。因此,如果您想创建PDF,请参阅第一个示例,并且不要使用<!-- -->。在HTML中,您可以在文档中留下两个注释字符。

那这对PDF

title: "Untitled" 
author: "Mario Dejung <[email protected]>" 
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 <[email protected]>" 
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} 

--> 
+0

不错的解决方案。我想我将来也会使用它们,但目前我正在寻找类似@CL的东西。回复。不管怎么说,还是要谢谢你! –