Reproducible Research — R Markdown
R Programming & Data Analytics / Reproducible Research — R Markdown

Reproducible Research — R Markdown

Intermediate 8 hrs 2 Concepts
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')
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. What is the primary purpose of yaml, chunks, and rendering?
Q2. Which R package is most relevant for this topic?
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. What is the primary purpose of parameterised reports?
Q2. Which R package is most relevant for this topic?
Functional Programming with purrr Shiny Web Applications