【问题标题】:Knit only until a specific chunk只编织到特定的块
【发布时间】:2020-05-30 15:10:07
【问题描述】:

有没有办法编织一个 html_document 直到一个特定的块?

假设我有这个 .Rmd 并且我只想编织一个 html_document 直到 cars 块:

---
title: "Untitled"
author: "Igor Kuivjogi Fernandes"
date: "14/02/2020"
output: html_document
---

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

R 降价

这是一个 R Markdown 文档。 Markdown 是一种用于创作 HTML、PDF 和 MS Word 文档的简单格式化语法。有关使用 R Markdown 的更多详细信息,请参阅http://rmarkdown.rstudio.com

当您单击 Knit 按钮时,将生成一个文档,其中包括内容以及文档中任何嵌入式 R 代码块的输出。您可以像这样嵌入 R 代码块:

summary(cars)

包括地块

您还可以嵌入绘图,例如:

plot(pressure)

请注意,echo = FALSE 参数已添加到代码块中,以防止打印生成绘图的 R 代码。

【问题讨论】:

    标签: r-markdown


    【解决方案1】:

    这个

    ---
    title: "Test"
    output: html_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ```{r cars}
    summary(cars)
    ```
    
    ```{r pressure, echo=FALSE}
    plot(pressure)
    ```
    

    产生这个:

    如果你添加一个控制全局选项的块......

    ---
    title: "Test"
    output: html_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    ```
    
    ```{r cars}
    summary(cars)
    ```
    
    ```{r setup2, include=FALSE}
    knitr::opts_chunk$set(eval = FALSE)
    ```
    
    ```{r pressure, echo=FALSE}
    plot(pressure)
    ```
    

    ...那么最后一个代码块没有执行,也没有情节:

    【讨论】:

    • @igorkf:我更改了我的答案以使其非常清楚。而这就是的答案。如果这对您不起作用,则与 Rmd 代码块无关。
    【解决方案2】:

    我找到了一种方法,但不是那么漂亮。 我已经选择了所有代码并按下Ctrl + Shift + C,所以注释了所有行:

    ---
    title: "Untitled"
    author: "Igor Kuivjogi Fernandes"
    date: "14/02/2020"
    output: html_document
    ---
    
    ```{r setup, include=FALSE}
    knitr::opts_chunk$set(echo = TRUE)
    

    R 降价

    这是一个 R Markdown 文档。 Markdown 是一种用于创作 HTML、PDF 和 MS Word 文档的简单格式化语法。有关使用 R Markdown 的更多详细信息,请参阅http://rmarkdown.rstudio.com

    当您单击 Knit 按钮时,将生成一个文档,其中包括内容以及文档中任何嵌入式 R 代码块的输出。您可以像这样嵌入 R 代码块:

    summary(cars)
    
    <!-- ## 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. -->
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-07-27
      • 2010-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-21
      • 2014-03-19
      相关资源
      最近更新 更多