Reproducible Research — R Markdown
R Markdown Documents
YAML, Chunks, and Rendering
An R Markdown document has three parts: YAML header (metadata), text (Markdown), and code chunks (R code).
# 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')
# See the code example above and adapt it to your data. # Always check your output with str() and head().
Parameterised Reports
Parameters allow one Rmd to generate multiple reports with different data.
# 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=.)))
# See the code example above and adapt it to your data. # Always check your output with str() and head().