R code
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
Quarto is the name of an open-source publishing system used for technical and scientific writing.
It lets you combine text, code, and outputs in one document—perfect for data science, research, and reproducible reports.
You can write in Python, R, Julia, or Observable JavaScript, and publish to formats like HTML, PDF, Word, and even full websites
It’s considered the next generation of R Markdown, and works with tools like Jupyter Notebooks, VS Code, and RStudio.
Because it is based on R Markdown, there is a wealth of related resources and books published on and using R Markdown. See some of on the examples books using R we will periodically using in the course.
R Markdown and Quarto are both tools for creating dynamic documents that combine code, text, and outputs (like plots or tables), but they differ in terms of design philosophy, features, and flexibility. Here’s a breakdown of their key differences:
| Feature | R Markdown | Quarto |
|---|---|---|
| Language Support | Primarily R | R, Python, Julia, JS |
| Execution Engine | knitr | Jupyter / native |
| Output Formats | Many | More + easier config |
| Interactivity | Limited | Rich (widgets, JS) |
| Project Support | Basic | Full project system |
| Extensibility | Moderate | High |
| Ideal For | R-centric reports | Multi-language docs |
Let’s go the the Quarto documentation for Markdown basics and more details on Figures
It is important to specific where the figure is located relative to your .qmd file. The path can be relative (giant_virus.jpg) or (images/giant_virus.jpg) or absolute (/home/pi_jlb_umass_edu/images/giant_virus.jpg).
In Quarto, a YAML block is a section at the top of a document that contains metadata and configuration settings. YAML stands for “YAML Ain’t Markup Language”, and it’s used to define things like the document title, author, output format, and more.
A YAML block is enclosed by triple dashes (---) at the beginning and end:
---
title: "My Analysis Report"
author: "Jeffrey Blanchard"
date: "2025-09-08"
format: html
editor: visual
---This block tells Quarto: - The title of the document. - The author name. - The date to display. - The output format (e.g., HTML, PDF, Word). - The editor preference (e.g., visual or source).
Here are some frequently used fields:
| Field | Description |
|---|---|
title |
Title of the document |
author |
Author name(s) |
date |
Date of publication |
format |
Output format (e.g., html, pdf, docx, revealjs) |
toc |
Table of contents (true or false) |
number-sections |
Number section headings |
theme |
Visual theme for HTML or slides |
code-fold |
Whether code chunks can be collapsed |
execute |
Controls code execution (e.g., echo, eval, freeze) |
bibliography |
Path to .bib file for citations |
filters |
Lua filters for advanced customization |
---
title: "Data Exploration"
author: "Jeffrey Blanchard"
format:
html:
toc: true
code-fold: true
theme: cosmo
embed-resources: true
execute:
echo: true
freeze: auto
---This configures: - An HTML output with a table of contents. - Collapsible code chunks. - A Bootstrap theme (cosmo). - Code execution settings.
Important for our class is the embed-resources: true line. This creates a single html file with the figures embeded in the file. If this line is not in the YAML block a new directory will be created which contains the images and is linked to the html file. This means that if you turn in this html file (without using embed-resources: true) the images will not be shown.
Quarto YAML is: - More consistent and extensible. - Supports nested configuration (e.g., format.html.toc). - Easier to manage across multi-format outputs (e.g., HTML and PDF from one source).
In Quarto, R code chunks are sections of code embedded in your document that get executed when the document is rendered. These chunks are enclosed in triple backticks and start with {r}. You can customize their behavior using chunk options, which control things like whether the code is shown, whether it’s executed, how results are displayed, and more.
Here’s a categorized list of the most useful options:
| Option | Description |
|---|---|
eval |
Whether to evaluate the code (TRUE or FALSE) |
echo |
Show the code in the output (TRUE or FALSE) |
include |
Include both code and output (TRUE or FALSE) |
error |
Show errors in output (TRUE or FALSE) |
warning |
Show warnings (TRUE or FALSE) |
message |
Show messages (TRUE or FALSE) |
| Option | Description |
|---|---|
results |
How to display results ("markup", "asis", "hide") |
fig.width |
Width of plots (in inches) |
fig.height |
Height of plots (in inches) |
fig.cap |
Caption for figures |
fig.align |
Alignment of figures ("left", "center", "right") |
| Option | Description |
|---|---|
cache |
Cache results to avoid re-running code |
freeze |
Freeze output to avoid re-execution unless explicitly updated |
| Option | Description |
|---|---|
tidy |
Automatically tidy code before execution |
collapse |
Collapse code and output together |
comment |
Prefix for output lines |
{r pressure-plot, fig.width=6, fig.height=4, fig.cap="Pressure vs Temperature"}
This chunk: - Hides the code (echo=FALSE) - Sets figure size - Adds a caption - Names the chunk (pressure-plot) for reference
Try a different Quarto theme
Create a lab report that has
plot(cars) in which the plot is sized to a figure width of 3 and height of 2This lab was created with assistance from UMass Copilot