2016-09-28 129 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的東西。回覆。不管怎麼說,還是要謝謝你! –