Advanced YAML settings

1. Advanced YAML settings

Welcome to the last chapter of this course! In this chapter, you're going to learn how to customize the style and appearance of the RMarkdown report you created in the last chapter. Just as with tweaking ggplot graphics, the goal of this is creating a data science product that stands out from the rest. In this first section of the chapter, we are going to look at the so-called YAML header, which is the primary configuration point of RMarkdown reports.

2. YAML

YAML is a recursive acronym for YAML Ain't Markup Language – so it explicitly isn't a markup language. That's true in the way that we don't use it to structure documents like with Markdown or HTML, rather we use it as some form of data specification. YAML documents or YAML headers usually start with three hyphens. Then, pairs of keys and values follow. In this example we have a key "receipt" followed by a value "Oz-Ware Purchase Invoice". The data in the YAML document can be ordered hierarchically, so in this example, the keys first_name and family_name belong to the customer key. This is specified with whitespace indentation. The amount of whitespace doesn't matter as long as parallel elements have the same left justification.

3. YAML headers in RMarkdown documents

Each RMarkdown document starts with a YAML header. As you have seen in the previous exercises, basic properties of the document, like title, subtitle, etc. can be specified here. However, other settings can also be specified. For instance, tweaks to the html output, like a custom style sheet, called a theme. Or custom colors for syntax highlighting, that is, how your R code is colored in the output. Notice the indentations here. The output key contains an html_document key, which in turn contains settings that are specific to html documents. If you wanted, you could also add settings that only apply to pdf documents. There are many more options, for example you could add a table of contents with a specific YAML key, and further tweak this table with more settings. All of these settings are documented in great detail in the RMarkdown reference of RStudio, so make sure to have a look at it.

4. Let's customize your report!

Let's now try out some YAML options in the exercises!