How to Set Default Yaml For R Markdown Documents?

I asked this in Stack Overflow but I didn't get any responses so far.

This is what I typically put at the top of my documents in R markdown:

---
title: Title
author: Amar Al-Zubaidi
date: \today
mainfont: Inconsolata Nerd Font
sansfont: Inconsolata Nerd Font
monofont: Inconsolata Nerd Font
fontsize: 11pt
table-use-row-colors: true
bibliography: /home/amarakon/Documents/bibliography.bib
csl: /home/amarakon/Documents/Citations/apa-no-initials.csl
classoption: letterpaper
output:
  pdf_document:
    keep_tex: true
    latex_engine: xelatex
    template: eisvogel
    number_sections: true
---

I do pretty much the same thing for every document.
In fact, the only thing I change for every document is the title.
I want to know how I can put all of these values in a file (except for the title), and change my compile command to read that file when compiling. This is the command I use to compile:

R -e "rmarkdown::render('file.Rmd')"

My end goal is to only have to put something like this in my Rmarkdown document:

---
title: my-title
---

See the section 'Shared Options' in https://garrettgman.github.io/rmarkdown/pdf_document_format.html .
Maybe that will help.

What do I exactly put in that file?
I tried to copy everything from my yaml at the top of the document, but it gave me errors when trying to compile. Here is the contents of _output.yaml:

author: Amar Al-Zubaidi
date: \today
mainfont: Inconsolata LGC
sansfont: Inconsolata LGC
monofont: Inconsolata LGC
fontsize: 11pt
colorlinks: true
table-use-row-colors: true
toc: true
lot: true
lof: true
geometry: margin=1in
bibliography: /home/amarakon/Documents/bibliography.bib
csl: /home/amarakon/Documents/Citations/apa-no-initials.csl
classoption: letterpaper
header-includes: |
  \usepackage{color, soul, ulem}
  \renewcommand{\ULdepth}{1pt}
output:
  bookdown::pdf_document2:
    toc_depth: 3
    keep_tex: true
    latex_engine: xelatex
    template: eisvogel

Also, how do I make that file apply for every R markdown file in every directory?

Sorry to hear that.
See https://github.com/rstudio/rmarkdown/issues/297
There the idea is presented to copy the yaml to (before) the actual file and then render the resulting file. Of course you could automate this with a cover function for the render

The _output.yaml file is only for the output section of the yaml.
Is there a different way I could set the default options (not just output)?

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.