In `_output.yml`, some parameters are getting ignored - r

I have defined certain pandoc options in _output.yml:
```
author: "abc"
date: "`r format(Sys.time(), '%d %B, %Y')`"
```
But, these get ignored, unless these are defined in the YAML header inside the R Markdown file.
Is this prohibited from including in the separate YAML file? Is so, could you please mention what other parameters should be defined inside the Markdown file.

An _output.yml file can only be used for setting the output formats, as explained within the bookdown book. So you can specify anything which relates to the output format (HTML/PDF/Word) such as:
html_document:
toc: TRUE
theme: flatly
pdf_document:
toc: FALSE
In your examples, the parameters you provide are about document content. So anything like author, title, date, fontsize can't be specified.
This issue has also been addressed within the GitHub issues of R Markdown for further reading.

Related

R Markdown: change the title of the "References" section?

I am writing a report with R Markdown in which I include references. The problem is that R markdown automatically includes references at the end of the report (without calling them with \printbibliography for example) and the section title is "References". I am writing in French so I would like the title to be "Références", but more generally is there any way to modify the title of that section?
Below is reproducible example:
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
---
# Partie 1
\cite{greenwood_financial_1989}
# Partie 2
bla bla
and here is the content of the references.bib file:
#article{greenwood_financial_1989,
title = {Financial Development, Growth and the Distribution of Income},
url = {https://www.nber.org/papers/w3189},
number = {3189},
journaltitle = {NBER Working Paper Series},
date = {1989},
author = {Greenwood, Jeremy and Jovanovic, Boyan}
}
Does anybody have a solution?
Here's the solution that combines this answer on doing something similar with bibtex and this one on the TeX required to do it in biblatex, plus #Ralf's comment about adding lang: fr
---
title:
author:
date:
abstract:
output:
pdf_document:
template: NULL
number_sections: true
citation_package: biblatex
bibliography: references.bib
biblio-style: bwl-FU
lang: fr
---
In my document, I used :
header-includes:
- \usepackage[french]{babel}
And your Contents section also changes.
I had a similar problem I wanted to place the bibliography above a supplemental section and placing <div id = "refs"></div> where you want the references successfully repositioned the section. I also had no problem renaming the section by simply changing the # title above that section. This did work for PDF output as well as HTML despite appearing to be an HTML only solution, though I was also using the markdown flavored ([#Smith2019]) references in the body of my document I don't know if using the LaTeX style will affect things.

References Truncated in Beamer Presentation prepared in Knitr/RMarkdown

I'm currently preparing a presentation in RStudio (using RMarkdown and Knitr, outputting to a Beamer presentation) that has quite a few references.
I'm using a pretty typical YAML header:
---
title: "Title"
author: "Me"
date: "February 27th, 2016"
output:
beamer_presentation
csl: ../../apa.csl
bibliography: ../../RefenceDesk.bib
---
This presentation compiles and the references appear as they should, but unfortunately they all appear on one slide (and actually run off the page). Is there any way to have the references appear on multiple slides?
{.allowframebreaks} is the solution for multislides bibliographies in beamer. It works out of the box with regular pandoc templates (see my previous answer). However, knitr has a setting that prevents it, by redefining \widowpenalties in its beamer template. You can verify that if you examine the .tex file with keep_tex: true.
In my opinion, this is a bug. A quick fix would be to reset \widowpenalties to its default value. It can be done in your yaml front matter:
---
title: Title
header-includes:
- \widowpenalties 1 150
output:
beamer_presentation
---
Then, you can indicate the reference section as such:
## References {.allowframebreaks}
As #David above said in the comments:
For me it didnt work with ## References {.allowframebreaks} but it worked out with # References {.allowframebreaks}.
I would like to point out that, apparently for the reference slide to work you have to create a last slide with the same heading level es set by slide_level: __ at the YAML section.
So, the user should set one of the following:
# References {.allowframebreaks}. for those using slide_level: 1, OR
## References {.allowframebreaks}. for those using slide_level: 2, OR
### References {.allowframebreaks}. for those using slide_level: 3 and so on...
While this goes outside of using the regular pandoc citation template, I have found another approach that can be used to put the references across slides but it relies on the natbib citation package.
In the YAML front matter, I added:
---
title: "Title"
output:
beamer_presentation:
citation_package: natbib
bibliography: ../../RefenceDesk.bib
biblio-style: "apalike"
---
The reference slide does not get a title and I cannot seem to adjust the font size (by using a \scriptsize at the end of the .Rmd file), but at least they appear coherently.
EDIT: For parsimony, I removed the csl: ../../apa.csl line, since natbib does not require it.

How to insert appendix after references in Rmd using Rstudio?

I am using Rstudio, to create a pdf / html document from an Rmd file. The header looks sth like this:
title: "Title"
author: "Me"
date: "`r format(Sys.time(), '%B %d, %Y')`"
bibliography: bibliography.bib
output:
html_document:
toc: true
number_sections: true
Now, I have some sections, and then include the references. After that, an appendix should follow, but I encounter the exact same problem as described here: Pandoc insert appendix after bibliography
There is a fixed solution in this thread, but I have no idea how I can do that within RStudio directly. To get the document, I just press the "Knit html" button, and do not run any pandoc commands myself. So where should I put the
--include-after-body
part, and how should the appendix rmd file look like?
As noted in the rmarkdown manual, you could use this syntax:
---
output:
html_document:
includes:
after_body: appendix.md
---
This is equivalent to the general way to add arbitrary pandoc arguments to a Rmd file:
---
output:
html_document:
pandoc_args: ["--include-after-body=appendix.md"]
---
The following might be easier; works if you knit to PDF, Word or HTML:
Everything I wanted to say in the main document.
# References
<div id="refs"></div>
\newpage
# Appendix
Some details that will bore the readers of the main document.
In the original post, this was also posted as an answer (few years after current question was asked): see https://stackoverflow.com/a/44294306/8234333 and https://stackoverflow.com/a/16428699/8234333

Inline R code in YAML for rmarkdown doesn't run

I'm trying to run inline R code in the YAML front matter before getting rmarkdown to run the file. However it isn't working for me. Here's an example:
---
title: "**Title**"
classoption: xcolor=dvipsnames
output:
beamer_presentation:
slide_level: 2
pandoc_args: [
"--bibliography", "`r paste('path/to/bib')`"
]
---
<!-- slide 1 -->
## Intro ##
Which throws an error:
pandoc-citeproc: could not find `r paste('path/to/bib')`
This is a simple example, but highlights my main problem. How do I get rmarkdown to run the inline R code in the YAML front matter?
It is a similar problem to these questions:
Manipulate RMarkdown metadata from within R code chunks
YAML current date in rmarkdown
This is how I solved this. I knit from RStudio. Curiously, I had to use one solution for the date and csl fields and a different solution for the bibliography field. !expr did not work in the date or csl lines (for me). And quoted r code didn't work in the bibliography line (for me). I have the bibliography and csl files in a package (inst/docs folder). rmarkdown files, which are not part of that package, use those.
---
title: "Title"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: html_document
bibliography: !expr system.file("docs", "my.bib", package = "MyPackage")
csl: '`r system.file("docs", "my.csl", package = "MyPackage")`'
---
# Introduction
Yada yada [#MyRef04].
# References
my.bib is the BibTex file with MyRef04. csl is the style file
This is a situation where one person maintains a package which has data, code, bibliography, etc. Others, potentially unknown to the package writer, install that package from GitHub and write or run rmarkdown files that use the package. The users almost certainly do not use Git or GitHub and I don't want them to have to download any extra files after installing the package from GitHub.
Update: After posting the above, I happened to install markdown from GitHub because I needed something in the development version. With version ‘1.7.5’ of rmarkdown on GitHub you can use r code in the bibliography line:
---
title: "Title"
date: '`r format(Sys.time(), "%d %B, %Y")`'
output: html_document
bibliography: '`r system.file("docs", "my.bib", package = "MyPackage")`'
csl: '`r system.file("docs", "my.csl", package = "MyPackage")`'
---
To install rmarkdown from GitHub
library(devtools)
install_github("rstudio/rmarkdown")
So I found a round about way of getting what I wanted. Rmarkdown I don't think allows R expressions/commands in the YAML, probably for a good reason. What I ended up doing was putting all the output yaml commands in a file called _output.Ryaml like so:
beamer_presentation:
slide_level: 2
includes:
in_header: "src/preamble.tex"
pandoc_args: [
"--bibliography", "`r paste('path/to/bib')`",
"--variable", "classoption:xcolor=dvipsnames",
"--variable", "fontsize:9pt"
]
Then in the main slides.Rmd file, was something like:
---
title: "**Title**"
author: Luke
---
<!-- slide 1 -->
## Intro ##
Then, I can generate the slides using the R code (which I put into a Makefile):
knitr::knit('_output.Ryaml', '_output.yaml')
rmarkdown::render('slides.Rmd')
unlink('_output.yaml')
Seems to be working well enough. If anyone's got a better idea, let me know!

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
---
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
---
In my case, I tried to knit multiple output-documents using bookdown and found this post which allowed me to get the desired result.
You can write the output-definition in your YAML header as follows:
---
output:
bookdown::pdf_document2:
template: "path-to-my-template"
bookdown::word_document2:
default
knit: (function(inputFile, encoding){
rmarkdown::render(inputFile, encoding = encoding,
output_dir = "my-output-path", output_format = "all") })
---

Resources