Explore more Quarto functionality and practice implementing it.
Today we will focus on:
Let’s start by playing around with the basic RStudio Quarto template a little more.
Open a fresh Quarto document by clicking:
File → New File → Quarto Document…
Enter Lab exercise in the Title field, keep
HTML as the default output format, and click
Create.
Save the document as lab1.qmd.
As you’re making changes, render often and see how your edits look in the finished document.
Let’s play around with the formatting of our document.
Remember that Markdown is a simple formatting language for plain text. You can find a useful overview in the Quarto Markdown Basics guide, and a broader collection of Quarto documentation in the Quarto Guide.
Some ideas of what you can try:
Compare the output with different numbers of # in
headings.
For example:
# First-level heading
## Second-level heading
### Third-level heading
Try adding:
mean(x)A line containing three dashes:
---
creates a horizontal rule.
You can add an image using Markdown syntax:

If you are using an image stored on your computer, it is good practice to keep it inside your project rather than linking to a file somewhere else on your computer.
For example, if you have an images folder inside your
project:

Render the document and make sure the image appears.
Another really useful feature is inline code. Instead of putting R code in a separate code cell, we can insert the result of an R expression directly into a sentence.
For example:
There are `{r} nrow(cars)` observations in the cars dataset,
and `{r} ncol(cars)` variables.
Render the document and see what happens.
The code itself disappears from the rendered sentence and is replaced with the result.
This is particularly useful when writing reports because values in the text can update automatically when the data or analysis changes.
Quarto also supports LaTeX-style equations.
For example, inline math can be written as:
$y = mx + b$
and a displayed equation as:
$$
y = mx + b
$$
We won’t spend much time on equations today, but you can find more details in the Quarto documentation on equations.
Add a few R code cells to your document.
For example:
```{r}
summary(cars)
```
Render the document and look at what appears.
In Quarto, cell options are typically added on lines beginning with
#| at the top of the code cell.
Try:
```{r}
#| echo: false
summary(cars)
```
What changes?
Now experiment with:
#| echo: false#| eval: false#| warning: false#| message: false#| include: falseTry to explain in your own words what each option controls.
You can find more options in the Quarto documentation on using R.
Code cells can also be given labels:
```{r}
#| label: cars-summary
summary(cars)
```
Labels help organize larger documents and allow us to refer to figures and tables.
Labels should be unique within a document.
Now create a figure:
```{r}
#| label: fig-cars
#| fig-cap: "Speed and stopping distance in the cars dataset."
plot(cars)
```
Because the label begins with fig-, Quarto recognizes
this as a figure that can be cross-referenced.
Elsewhere in your document, add:
See @fig-cars.
Render the document.
Notice that Quarto automatically numbers the figure, adds the caption, creates a cross-reference, and updates the reference if the figure number changes.
Document-level options belong in the YAML header at the top of the
.qmd file.
Change your YAML to something like:
---
title: "Lab exercise"
author: "Your name"
format:
html:
toc: true
toc-depth: 3
editor: visual
---
Render the document.
What changed?
Try changing toc-depth to 2 or
4.
More details are available in the Quarto HTML documentation.
So far we have been rendering our .qmd file to HTML.
Quarto can create many other formats from the same source document.
Try changing:
format: html
to:
format: docx
Render again and compare the Word version with the HTML version.
Now change back to HTML before continuing.
For much of this course, we will use GitHub Flavored Markdown (GFM) because it displays well directly on GitHub and integrates naturally with our Git/GitHub workflow.
In Quarto, GFM is specified as:
format: gfm
Try changing your output format to gfm and render the
document.
Look at the files Quarto creates. We will work much more with this format once we begin using Git and GitHub.
Quarto can also create PDF documents. To render a Quarto document to PDF, you need a TeX installation. We recommend TinyTeX, a relatively small version of TeX that works well with Quarto.
If you don’t already have a TeX installation, you can install TinyTeX directly through Quarto.
In RStudio, open the Terminal tab (next to the Console) and enter:
quarto install tinytex
Follow the prompts to complete the installation. You only need to install TinyTeX once on your computer.
Once it is installed, change the output format in your Quarto document to:
format: pdf
and click Render.
If you want to check whether TinyTeX is installed, you can enter this in the Terminal:
quarto list tools
You should see TinyTeX listed as installed.
Now practice what you’ve learned by creating a brief CV in Quarto.
Start a new Quarto document for this exercise.
The title should be your name, and you should include headings for at least:
Each section should include a bulleted list of relevant degrees, positions, experiences, or skills.
Also:
---) to visually separate two
parts of your CVRender your CV to HTML.
If you’re comfortable, share the rendered result or a screenshot with
the class in the lecture-chat channel in Slack.
Choose one thing you would like to change or add to your Quarto document that we have not explicitly shown you how to do.
For example, you might want to:
Ask an AI tool for help.
As you work, give the AI enough context to know that you are working
in a Quarto .qmd file and what output format you are
using.
Then:
Be prepared to briefly discuss:
The goal is not simply to get AI to produce the right syntax. The goal is to practice using AI to help you learn while still verifying and understanding what it suggests.
If time permits, work in small groups to explore what else Quarto can do.
Browse the Quarto Gallery.
Look at examples of:
Discuss with your group:
Which application do you think is the coolest or potentially most useful for your own work?
Be ready to report back to the class.
END LAB 1