Exercises: Introduction to Quarto
Overview
These exercises introduce you to key elements of Quarto documents. You will have the opportunity to explore how these elements enable you to create quality documents that effectively communicate and document your analyses and findings.
There are five exercises to enhance your familiarity with Quarto documents. The first exercise introduces you to options for rendering a Quarto file into a document. The second exercise focuses on understanding YAML headers, where you will learn to customize metadata such as title and author. Next, you will dive into the document body, exploring formatting options to organize your content effectively. During the fourth exercise, you will be introduced to code chunks, allowing you to embed and execute code in R, Python, or Julia, creating dynamic reports that showcase your analysis. The final exercise provides an opportunity to apply your new skills by creating a Quarto report. Through these exercises, you will develop essential skills to create professional Quarto documents.
For additional resources on Quarto documents, please visit:
Set up
- Complete the Prework steps to download the exercise materials
Exercise 1: Rendering
Rendering in Quarto documents refers to the process of converting a Quarto file, which is written in a markdown-like syntax, into a final output format such as HTML, PDF, or Word. During rendering, the Quarto system interprets the markdown content, processes embedded R code chunks, and generates the respective output by applying formatting specified in the YAML header. This transformation allows users to produce well-structured and visually appealing documents that incorporate text, data visualizations, and analysis results seamlessly, making it an essential step in creating dynamic reports and presentations.
Tasks
-
Hint
In the terminal:quarto render 1_rendering/<input file name>
-
Hint
In the console:quarto::quarto_render("./1_rendering/<input file name>")
Exercise 2: YAML metadata
A YAML (Yet Another Markup Language) header is a crucial component of Quarto documents that defines metadata for the document, typically enclosed within a pair of triple-dashed lines at the beginning of the file. It allows users to specify important information such as the document’s title, author, date, and output formats (like HTML, PDF, or Word). Additionally, YAML headers can include parameters to control formatting options and customize the behavior of the document, such as including bibliographies or setting specific themes. By using a YAML header, authors can ensure that their documents are well-organized and professionally presented.
Tasks
Bonus tasks
-
Hint
Using templates
-
Hint
Addoutput_format = "all"
argument toquarto::quarto_render()
Exercise 3: Document body
The document body of a Quarto document is the main content area where the narrative, analysis, and findings are presented. This section is typically written in markdown format, allowing users to easily incorporate various elements such as headings, paragraphs, lists, tables, and images. The importance of the document body lies in its role as the primary medium for communicating information and insights to the reader; it organizes thoughts and results in a coherent and engaging manner. A well-structured document body enhances readability and comprehension, enabling the audience to grasp complex ideas and data more effectively. By integrating both text and visual elements, the document body plays a critical role in making the overall document informative and visually appealing.
Tasks
Open 3-document_body.qmd
and make the following changes to the document:
Inline:
Block:
Exercise 4: Code chunks
Code chunks in a Quarto document are sections of embedded code, typically written in R or other programming languages, that allow users to perform data analysis, generate visualizations, and execute computations directly within the document. These chunks are enclosed by specific delimiters, enabling Quarto to recognize and execute the code during the rendering process. The importance of code chunks lies in their ability to integrate dynamic content with narrative text, making it possible to showcase real-time analysis and results alongside explanatory writing. This functionality enhances reproducibility, as the document can simultaneously present the code and its output, facilitating transparency and allowing others to verify or replicate the findings. By incorporating code chunks, Quarto documents become interactive and informative, transforming static reports into live analytical narratives.
Tasks
Open 4_code_chunks.qmd
and make the following changes to the rendered document:
Exercise 5: Your turn!
You have now learned how to render a Quarto document and how to change the look and feel of a Quarto document by customizing the YAML metadata, inline and block elements of the text body, and code chunks. Now it is time to apply these skills by creating a Quarto document from scratch.
Tasks
Do your best to recreate the document below. When rendered as a .html
, your file should look exactly the same aside from the publishing date.
Use the following steps to guide you:
-
Hint
File > New File > Quarto Document
<- read.csv("data/plover_data.csv")
data <- data$Males plovers
Hint
The chunk options you are looking for areecho
and fig-cap
. Use hist(plovers)
to generate the plot.
Bonus tasks