【问题标题】:List the full code of a knitr-type document at the end of the same document在同一文档的末尾列出一个knitr类型文档的完整代码
【发布时间】:2015-01-13 23:04:50
【问题描述】:
One chunk silently generates output.

```{r, echo = FALSE}
summary(cars)
```

How can the same chunk be automatically listed at the end like this?

```
summary(cars)
```

knitr::purl 带有参数 eval = FALSE 如果存在,则可以使用。

最好按名称列出各个块。

【问题讨论】:

  • 您在寻找eval =FALSE 选项吗?
  • 是的,purl 没有,我正在寻找类似的东西。不会,因为块上的 eval = FALSE 会阻止它生成任何输出。 echo = "end_of_document" 是另一种思考方式。
  • AFAIK purl 不评估代码,但是我似乎无法避免创建输出文件,尽管文档声称如果 output=NULL 代码应该作为字符向量返回跨度>
  • @baptiste 你确定吗?文档说purlknittangle = TRUE 的包装,在评估代码之前,我在knit 源中看不到任何以tangle = TRUE 为条件的内容。
  • 你是对的,出于某种原因,我认为 purl 没有运行代码。那真不幸。我经常使用不同的策略,我的 R 代码在一个单独的 R 文件中,我用read_chunk() 引用这些块。使用此工作流程,将 R 文件打印为文本将是微不足道的。

标签: r knitr sweave r-markdown


【解决方案1】:

我在knitr book第一版的第12.1.4节中已经提到过,基本上是:

```{r ref.label=knitr::all_labels()}
```

【讨论】:

  • 在你的online documentation 中搜索“重用块”也找到了它。我错过了搜索术语。
猜你喜欢
  • 1970-01-01
  • 2018-06-13
  • 1970-01-01
  • 2015-12-30
  • 2021-08-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多