'How to Set Default Yaml For R Markdown Documents?

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
---


Solution 1:[1]

I answered a similar question not that long ago using this information.

Since I had worked on that question, I only had to clone my last template and update the skeleton to create your template.

You won't have a YAML with just your title. However, all of the elements that you specified you wanted would be pre-written in the RMD file when you open a new file using this template.

You can see this repository at fraupflaume/customYAML2.

To install this template (it's not a package per se; there's no library):

devtools::install_github("fraupflaume/customYAML2")

When you want to start a new RMD script, go to templates -> Custom YAML -> customYAML2.

enter image description here

If you wanted to change this down the road, you can fork or clone that repository and edit it to your heart's content.

enter image description here

BTW:: let me know if you want me to remove the images. (It has your name in them: here and on Github.)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kat