26 Y

26.1 YAML

A structured format for information

You'll most commonly encounter YAML in the header of an R Markdown document. It consists of key and value pairs separated by a colon, where the key is an unquoted label, like title, and the value is quoted or unquoted text like "My Document" or a further list of keys and values.

---
title: "My Document"
subtitle: "It's Just a Demo"
author: "Me"
date: "2024-09-05"
output:
  html_document:
    theme: spacelab
    highlight: tango
    toc: true
    toc_float:
      collapsed: false
      smooth_scroll: false
    toc_depth: 3
    number_sections: false
---

The spacing and line breaks need to be exactly right or YAML won't parse and you will get error messages when you try to knit the R Markdown document. For example, the header above won't knit if you change the spacing before theme: spacelab like this:

output: 
  html_document:
  theme: spacelab

YAML stands for YAML Ain't Markup Language.