Specifying multiple simultaneous output formats in

2019-04-19 13:04发布

问题:

Can I write a YAML header to produce multiple output formats for an R Markdown file using knitr? I could not reproduce the functionality described in the answer for the original question with this title.

This markdown file:

---
title: "Multiple output formats"
output: 
    pdf_document: default
    html_document:
      keep_md: yes
---

# This document should be rendered as an html file and as a pdf file

produces a pdf file but no HTML file.

And this file:

---
title: "Multiple output formats"
output: 
  html_document:
    keep_md: yes
  pdf_document: default
---

# This document should be rendered as an html file and as a pdf file

produces an HTML file (and an md file) but no pdf file.

This latter example was the solution given to the original question. I have tried knitting with Shift-Ctrl-K and with the Knit button in RStudio, as well as calling rmarkdown::render, but only a single output format is created, regardless of the method I use to generate the output file.

Possibly related, but I could not identify solutions:

  • How do I produce R package vignettes in multiple formats?
  • Render all vignette formats #1051
  • knitr::pandoc can't create pdf and tex files with a single config #769
  • Multiple formats for pandoc #547
  • An allusion to multiple output format support in a three year old RStudio blog post

Using R version 3.3.1 (2016-06-21), knitr 1.14, Rmarkdown 1.3

回答1:

I actually briefly mentioned in Render all vignette formats #1051 and you missed it:

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

It is documented on the help page ?rmarkdown::render.