0

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

1 Answer 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.)

4
  • Thank you so much! But I use VIM to edit my .Rmd files and not Rstudio. How can I specify the custom YAML template without Rstudio? Also, is having a git repository mandatory? Because I want to change the settings a bit and have multiple templates. I want to do it locally on my computer without a git repository.
    – Amarakon
    Mar 16 at 3:53
  • No, Git is not necessary. The very first hyperlink I provided will bring you to a package that is designed around making templates. I have used VIM as an interface, so I don't know if that will work, though. It may give you ideas that will work, if that, in and of itself doesn't.
    – Kat
    Mar 16 at 13:15
  • Thanks. How do I specify the template without using Rstudio?
    – Amarakon
    Mar 16 at 16:48
  • Also, If I do not install the template using git, in which directory do I place the files?
    – Amarakon
    Mar 16 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.