đ Introduction
R Markdown and Quarto are powerful tools for creating dynamic documents that combine text, R code, tables, visualizations, and results in a single file. They support reproducible research by automatically updating outputs whenever the source code changes. Documents can be rendered into formats such as HTML, PDF, Word, presentations, websites, and books.
Information
đ¯ Why Learn R Markdown and Quarto?
- Create reproducible reports.
- Combine code, results, and explanations in one document.
- Generate professional reports automatically.
- Produce presentations, websites, and books.
- Share data analysis in a consistent and reproducible manner.
đ R Markdown vs Quarto
| Feature | R Markdown | Quarto |
|---|---|---|
| Primary Language | R. | R, Python, Julia, and more. |
| File Extension | .Rmd | .qmd |
| Cross-Language Support | Limited. | Built-in. |
| Publishing | Reports and presentations. | Reports, books, websites, dashboards, and presentations. |
| Recommended for New Projects | Existing workflows. | Yes. |
đĻ Installing Required Packages
Install Required Packages
install.packages("rmarkdown")
install.packages("knitr")
library(rmarkdown)
library(knitr)đ Basic Structure of an R Markdown Document
An R Markdown document consists of a YAML header, Markdown text, and executable R code chunks.
Simple R Markdown Document
---
title: "Sales Report"
author: "John Doe"
date: "2026-07-09"
output: html_document
---
# Introduction
This report analyzes monthly sales.
```{r}
summary(cars)
```đ Basic Structure of a Quarto Document
Quarto uses a similar structure but includes a simplified YAML configuration.
Simple Quarto Document
---
title: "Sales Report"
format: html
---
# Introduction
This report analyzes monthly sales.
```{r}
summary(cars)
```đ Markdown Syntax
| Syntax | Purpose |
|---|---|
| # Heading | Level 1 heading. |
| ## Heading | Level 2 heading. |
| **Bold** | Bold text. |
| *Italic* | Italic text. |
| - Item | Bullet list. |
| 1. Item | Numbered list. |
| [Text](URL) | Hyperlink. |
đģ R Code Chunks
Code chunks contain executable R code enclosed within triple backticks.
R Code Chunk
```{r}
x <- 10
y <- 20
x + y
```âī¸ Chunk Options
Chunk options control how code and results appear in the output document.
| Option | Description |
|---|---|
| echo | Display the R code. |
| eval | Execute the code. |
| warning | Display warning messages. |
| message | Display informational messages. |
| fig.width | Figure width. |
| fig.height | Figure height. |
Chunk Options Example
```{r echo=FALSE, warning=FALSE}
summary(iris)
```đ Including Tables
Create a Table
library(knitr)
kable(
head(iris),
caption = "Sample Iris Dataset"
)đ Including Charts
Charts generated inside code chunks automatically appear in the rendered document.
Plot Example
```{r}
plot(
iris$Sepal.Length,
iris$Sepal.Width,
col = "blue",
pch = 19
)
```đ Generating Reports
R Markdown and Quarto documents can be rendered into multiple output formats.
| Format | Example |
|---|---|
| HTML | Interactive web report. |
| Printable report. | |
| Word | Microsoft Word document. |
| Presentation | Slides. |
| Website | Static website. |
đ¤ Rendering Documents
Render an R Markdown File
library(rmarkdown)
render(
"report.Rmd"
)Render a Quarto Document
quarto render report.qmdđ Parameters in R Markdown
Parameters allow reports to be generated dynamically using different input values.
Parameterized Report
---
title: "Sales Report"
params:
year: 2026
output: html_document
---
```{r}
params$year
```đ¨ Quarto Callouts
Quarto supports built-in callouts for highlighting important information.
Quarto Callout
::: {.callout-note}
This report was generated automatically using Quarto.
:::đ Creating Presentations
Both R Markdown and Quarto can generate presentations using formats such as Reveal.js and Beamer.
Reveal.js Presentation
---
title: "Sales Presentation"
format: revealjs
---
# Sales Summary
- Revenue increased.
- Expenses decreased.
- Profit improved.đ Creating Websites
Quarto can generate complete websites from multiple documents.
Website Configuration
project:
type: website
website:
title: "My Data Science Website"đ Real-World Example
A data analyst prepares a monthly business report that includes descriptive statistics, visualizations, and predictive models. The report is written in Quarto so that every month, updated data automatically produces a new HTML report with refreshed tables and charts.
Monthly Business Report
---
title: "Monthly Sales Report"
format: html
---
# Sales Summary
```{r}
summary(iris)
plot(
iris$Sepal.Length,
iris$Petal.Length
)
```đ Report Generation Workflow
đ Common Functions and Commands
| Function/Command | Purpose |
|---|---|
| render() | Renders an R Markdown document. |
| kable() | Creates formatted tables. |
| quarto render | Renders a Quarto document. |
| echo | Controls code visibility. |
| eval | Controls code execution. |
| fig.width | Sets figure width. |
| fig.height | Sets figure height. |
â ī¸ Common Mistakes
| Mistake | Explanation | Solution |
|---|---|---|
| Using incorrect YAML syntax | Documents may fail to render. | Ensure proper indentation and formatting. |
| Forgetting to install required packages | Rendering may fail due to missing dependencies. | Install and load necessary packages before rendering. |
| Leaving unnecessary code visible | Reports become cluttered. | Use echo=FALSE to hide implementation details. |
| Hardcoding values | Reports become difficult to reuse. | Use parameters for dynamic report generation. |
đĄ Best Practices
- Use Quarto for new projects that may involve multiple programming languages.
- Write clear Markdown explanations alongside code.
- Organize reports with meaningful headings and sections.
- Hide unnecessary code while displaying important results.
- Use parameters to generate reusable reports.
- Include tables and visualizations to improve readability.
- Test rendering regularly throughout development.
Best Practice
đ Summary
R Markdown and Quarto enable the creation of dynamic, reproducible documents that integrate text, code, tables, and visualizations. In this chapter, you learned the structure of R Markdown and Quarto documents, Markdown syntax, code chunks, chunk options, table generation, chart integration, rendering documents, parameterized reports, presentations, websites, and report publishing. Mastering these tools allows you to automate report generation, improve reproducibility, and communicate analytical results professionally across multiple output formats.