r - R Markdown 中的多组共享选项

标签 r knitr pandoc reveal.js

是否可以为 R Markdown 设置多组共享选项?

这是我的问题:我有一个包含一堆 Markdown 文件的文件夹。这些文件可以分为两组:

  • html_document
  • revealjs::revealjs_presentation

我想从这些组中提取出通用的 YAML 代码。现在我知道我可以创建一个 _output.yaml 文件来捕获常见的 YAML,但我基本上需要有这些文件中的两个,每个输出格式一个.

看到pandoc_args的使用提示here我试了一下,如下所示:

---
title: Document Type 1
output:
  html_document:
    pandoc_args: './common-html.yaml'
---

---
title: Document Type 2
output:
  revealjs::revealjs_presentation:
    pandoc_args: './common-reveal.yaml'
---

但是使用此设置不会处理包含的 YAML 文件中的选项。

如有任何其他建议,我们将不胜感激!

最佳答案

您可以在同一个 _output.yaml 文件中指定多个输出格式,如下所示(只是一些示例选项):

html_document:
  self_contained: false
revealjs::revealjs_presentation:
  incremental: true

然后你必须render all output formats这不能直接使用 RStudio GUI 完成。相反,您必须在 R 控制台中输入以下内容:

rmarkdown::render(input = "your.Rmd",
                  output_format = "all")

理想情况下,确保 .Rmd 文档本身的 YAML 前端内容中没有 output 键。否则 _output.yaml 文件中的输出选项可能会被覆盖。不幸的是,我找不到关于确切行为的全面文档。到目前为止我的一些观察:

  • .Rmd 文档本身的 YAML 前端定义的输出选项总是 override those specified in the shared options file _output.yaml .
  • .Rmd 文档本身的 YAML 前端使用默认选项集(如 pdf_document: default)指定输出格式完全覆盖 _output.yaml。但是,如果您没有明确指定默认选项(如 output: pdf_document; 一次只能用于单一输出格式),则 _output.yaml 内容为受到充分重视。
  • 如果您在 _output.yaml 中指定了多种输出格式的选项,在 RStudio 中按下编织按钮时只会呈现第一个(即使您明确按下编织成 HTML/PDF/Word)。您还必须使用 rmarkdown::render(output_format = "all") 来呈现其他格式。

关于r - R Markdown 中的多组共享选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45385127/

相关文章:

r - pandoc 和 rmarkdown : Can't fetch an image one level above a rmarkdown document

r - 如何使用 purrr reshape 模拟函数的输出

java - Snowflake 通过 R/RJDBC - 无法检索 JDBC 结果集

r - 在 rmarkdown/knitr 中的 block 之前和之后插入 html 代码

r - 使用 jekyll、rmarkdown 和 github : how to display images 写博客

pdf - Pandoc Markdown 到 Latex PDF : table with alternating row colors?

r - 使用 MuMIn::dredge 时模型无法收敛

r - 连接两个数据表,仅使用第二个dt中的一列

knitr - 在Rstudio服务器中编译Rmd时.tex文件保存在哪里

pdf - Pandoc Markdown 到 Latex PDF : table merges rows in single row?