Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 views
in Technique[技术] by (71.8m points)

r - Specifying multiple simultaneous output formats in knitr

I would like to be able to specify multiple output formats at the same time, for instance html_document and a pdf_document. I know that this can be done very simply with something like

---
  output: [html_document, pdf_document]
---

I might have some of that syntax off, but I can not seem to find the documentation anywhere. I have recently discovered knitr-bootstrap and love it. It is what I have been looking for to be able to dynamically hide my code and output blocks.

Unfortunately, by default, the YAML block for the knitr-bootstrap invocation is quite complex and I do not know how to specify multiple outputs for this.

I have looked at the YAML spec and tried a few different things but I am at a loss. Below is my current YAML frontmatter.

---
title: "Beta Regression Comparison"
opset: bootstrap
output:
  knitrBootstrap::bootstrap_document:
    title: "Beta Regression Comparison"
    theme: Simplex
    highlight: Solarized - Light
    theme.chooser: FALSE
    highlight.chooser: FALSE
    menu: FALSE
  pdf_document
---
question from:https://stackoverflow.com/questions/25078572/specifying-multiple-simultaneous-output-formats-in-knitr

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The solution is to change pdf_document to pdf_document: default. I can't unfortunately find a reference for this syntax in the official documentation. If however you open a RMarkdown document in a recent version of RStudio, click Knit HTML and then Knit PDF, it uses this : default syntax.

The syntax is:

---
output:
  html_document:
    keep_md: yes
  pdf_document: default
---

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...