11.3 Structure of R Markdown
YAML header specifying several document options such as the output format, author and date e.t.c.
text written with Markdown syntax,
R code chunks with the code that needs to be executed.
The basic structure of a R markdown is shown below:
Other YAML options include the following:
fontsize to specify the font size e.t.c.
toc: true to include a table of contents at the start of the document
For example, the YAML below specifies an HTML document with font size 12pt, and includes a table of contents where 2 is the lowest level of headings. The date of the report is set to the current date by writing the inline R expression 2023-02-05.
---
: "An R Markdown document"
title: "Paula Moraga"
author: "`r Sys.Date()`"
date: 12pt
fontsize:
output:
html_document: true
toc: 2
toc_depth---
To generate a document from the .Rmd file, we can use the Knit button in the RStudio IDE or use the render() function of the rmarkdown package. The render() function has an argument called output_format where we can select the format we want for the final document.