Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying multiple simultaneous output formats in knitr (new)

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

like image 927
Jeff Avatar asked Jun 21 '17 20:06

Jeff


People also ask

What does knitr :: Opts_chunk set echo true mean?

The first code chunk: ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` is used to specify any global settings to be applied to the R Markdown script. The example sets all code chunks as “echo=TRUE”, meaning they will be included in the final rendered version.

What is the difference between Markdown and Rmarkdown?

R Markdown is an extension of the markdown syntax. R Markdown files are plain text files that typically have the file extension . Rmd . They are written using an extension of markdown syntax that enables R code to be embedded in them in a way which can later be executed.

What are the three types of sections in an Rmarkdown document?

There are three basic components of an R Markdown document: the metadata, text, and code.

How do you use the knitr in RStudio?

If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it.


1 Answers

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.

like image 100
Yihui Xie Avatar answered Oct 07 '22 23:10

Yihui Xie