1 Learning goals

  • Understand what R Markdown is and how it works under the hood (knitr → Pandoc → output).
  • Know when to use it (and when not to).
  • Get a quick syntax cheat-sheet for Markdown + code chunks.
  • Learn essential chunk options and reproducible-research tips.

TL;DR: R Markdown lets you combine text, code, and outputs in one document you can knit to HTML/PDF/Word for fully reproducible reports.

2 What is R Markdown?

R Markdown is a plain-text authoring format that blends Markdown for writing with R code (and other languages) for computation. You write a single .Rmd file and knit it to produce polished documents (HTML/PDF/Word), slides, or dashboards.

Under the hood:

  1. knitr runs your code chunks and weaves results into Markdown.
  2. Pandoc converts the Markdown to your chosen output format.
flowchart LR
    A[.Rmd] -→ B[knitr: execute R code]
    B -→ C[Markdown + results]
    C -→ D[Pandoc: convert]
    D -→ E[HTML / PDF / Word / Slides]

3 Some Basic Markdown Syntax Examples

You can also add formatting, links, images, and more to your document. Here are some examples:

3.1 Headers

# This is an H1

## This is an H2

3.2 Emphasis

*This text will be italic*This text will be italic
**This text will be bold**This text will be bold

3.3 Lists

Unordered:

- Item 1
- Item 2
  - Item 2a
  - Item 2b
  • Item 1
  • Item 2
    • Item 2a
    • Item 2b

Ordered:

1. Item 1
2. Item 2
3. Item 3
   - Item 3a
   - Item 3b
  1. Item 1
  2. Item 2
  3. Item 3
    • Item 3a
    • Item 3b

3.4 Others

Inline code: Min. : 4.0 , 1st Qu.:12.0 , Median :15.0 , Mean :15.4 , 3rd Qu.:19.0 , Max. :25.0 , Min. : 2.00 , 1st Qu.: 26.00 , Median : 36.00 , Mean : 42.98 , 3rd Qu.: 56.00 , Max. :120.00 → Min. : 4.0 , 1st Qu.:12.0 , Median :15.0 , Mean :15.4 , 3rd Qu.:19.0 , Max. :25.0 , Min. : 2.00 , 1st Qu.: 26.00 , Median : 36.00 , Mean : 42.98 , 3rd Qu.: 56.00 , Max. :120.00
Links: [R Project](https://www.r-project.org/)R Project Images

![R Logo](https://www.r-project.org/logo/Rlogo.png)R Logo

Quotes and footnotes:

> A quoted thought.
---
A sentence with a footnote.^[Footnote text.]

Mathematics (LaTeX):

Inline: $E = mc^2$\(E = mc^2\) Block:

$$
\int_a^b f(x)dx = F(b) - F(a)
$$

\[ \int_a^b f(x)dx = F(b) - F(a) \]

4 YAML metadata block

  • YAML metadata block is at the top of an R Markdown document and is enclosed by --- lines. For example:
  ---
  title: "My Document"
  output: html_document
    theme: readable
    toc: true
    toc_depth: 2
    toc_float: true
    number_sections: true
  date: "2025-09-23"
  ---

5 Code Chunks

  • R code chunks are enclosed by triple backticks and {r}. For example:

    summary(cars)
    ##      speed           dist       
    ##  Min.   : 4.0   Min.   :  2.00  
    ##  1st Qu.:12.0   1st Qu.: 26.00  
    ##  Median :15.0   Median : 36.00  
    ##  Mean   :15.4   Mean   : 42.98  
    ##  3rd Qu.:19.0   3rd Qu.: 56.00  
    ##  Max.   :25.0   Max.   :120.00
  • You can customize code chunks with options like echo, eval, message, warning, etc. For example:

    • echo: whether to show the code in the output (default: TRUE)
    • message/warning: whether to show messages or warnings (default: TRUE)
    • eval: whether to evaluate the code (default: TRUE)
    • results: how to display results (default: “markup”)
    • fig.width/fig.height: size of plots (default: 7, 5)
    • fig.align: alignment of plots (default: “center”)
    • fig.cap: caption for plots (default: NULL)
    • Label: a unique identifier for the chunk like {r my_chunk}