Reproducible Research — R Markdown
Intermediate
8 hrs
2 Concepts
Your Learning Map
📌 You already know
You can analyse data and make plots.
🎯 You'll learn here
Weaving code, output and prose into one reproducible document with R Markdown / Quarto, including parameterised reports.
🌍 Where it's used
Turning analysis into a shareable report or thesis that re-runs itself — the heart of reproducible research.
🔗 Unlocks next
The reporting layer for the capstone project.
M1
R Markdown Documents
Concept 1
YAML, Chunks, and Rendering
An R Markdown document has three parts: YAML header (metadata), text (Markdown), and code chunks (R code).
R
# In report.Rmd:
# ---
# title: 'Analysis Report'
# date: '`r Sys.Date()`'
# output:
# html_document:
# toc: true
# theme: flatly
# ---
#
# {r setup, include=FALSE} # knitr::opts_chunk$set(echo=TRUE, warning=FALSE) #
rmarkdown::render('report.Rmd')
R — An inline report value
LIVE READY
Output (verified)
[1] "This report summarises 32 cars."
Solved Examples
Example 1
Apply the concept of YAML, Chunks, and Rendering to a sample dataset. Show at least two approaches.
# See the code example above and adapt it to your data. # Always check your output with str() and head().
Self-Assessment (2 questions)
Q1. In an R Markdown document, executable R code lives in:
R runs inside fenced code chunks; the YAML header sets document metadata.
Q2. The YAML header at the top of an .Rmd file sets:
The YAML front matter configures metadata and the output format of the rendered document.
Concept 2
Parameterised Reports
Parameters allow one Rmd to generate multiple reports with different data.
R
# In YAML:
# params:
# subject: 'Math'
# In document: params$subject
# Render for Science:
rmarkdown::render('report.Rmd', params=list(subject='Science'))
# Render all subjects:
c('Math','Science','English') |>
walk(~rmarkdown::render('report.Rmd', params=list(subject=.)))
Solved Examples
Example 1
Apply the concept of Parameterised Reports to a sample dataset. Show at least two approaches.
# See the code example above and adapt it to your data. # Always check your output with str() and head().
Self-Assessment (2 questions)
Q1. Parameterised reports let you:
Declaring params lets one .Rmd produce many reports (e.g. per region) by changing inputs.
Q2. Parameters declared in YAML are accessed in code as:
Inside the document, the params list exposes each parameter as params$name.