2 + 2[1] 4
By the end of this lesson, you will be able to:
Quarto is a tool for creating reproducible documents that combine writing and data analysis in one place. A Quarto document can include text, code, results, tables, and figures so that your report updates automatically when your analysis changes.
In public health, Quarto supports transparency and accuracy by keeping your analysis and your writing connected.
In this course, all homework assignments and projects will be written in Quarto.
A reproducible document is one where another person (or future you) can:
Reproducibility helps prevent errors that happen when people copy and paste numbers or figures from the Console into a report.
A Quarto document typically has three pieces:
You will see all three in this lesson.
To create a new Quarto document:
To render:
When you render, Quarto runs the code chunks from top to bottom and builds the final output.
Markdown is a simple way to format text. In this course, Markdown will be used for headings, lists, emphasis, links, and section organization.
Headings help organize reports. In Markdown, headings use the number sign.
Example:
# Main section
## Subsection
### Smaller subsection
Example:
**bold text**
*italic text*
Example:
- first item
- second item
- third item
Markdown keeps your writing clean and readable.
R code is written inside code chunks. Code chunks run when you render the document.
Here is a simple code chunk:
2 + 2[1] 4
You can run code in two ways:
In this course, you should always render your document before submitting so your outputs are up to date.
Below we create a small vector and compute summary statistics.
ages <- c(21, 34, 29, 45, 38, 41)
mean(ages)[1] 34.66667
sd(ages)[1] 8.687155
length(ages)[1] 6
Inline code allows you to insert R results directly into a sentence. This is one of the most important skills in the course because it prevents copy and paste errors.
Inline code looks like this inside a sentence:
The sample included 6 participants, and the mean age was 34.7 years.
When you render, Quarto replaces the inline code with the calculated value.
Inline code helps you:
In this course, students are expected to use inline code for reported statistics whenever possible, especially in Projects 2 through 4.
Sometimes you want to show the results but hide the code (for a polished report). You can hide code using an option at the top of the chunk.
[1] 34.66667
In the rendered document, the code will be hidden and only the result will appear.
Avoid these common issues:
A simple rule is: if a number appears in your report, ask yourself whether it was produced by R during rendering.
In this course, students are expected to:
Perfection is not expected. Consistent effort and honest engagement are the priority.
Students will:
Goal: Establish documentation habits early
Create a new section in your own homework file and complete the tasks below.
Here is a starter example you may adapt:
x <- c(4, 6, 9, 12, 15, 18)Write a sentence like:
The sample size was 6, the mean was 10.67, and the standard deviation was 5.35.
Quarto allows you to combine writing and analysis. Markdown organizes your text. Code chunks run R. Inline code inserts calculated results into sentences. Reproducibility is a core skill for public health data science.
Next week, we will begin data visualization using ggplot2 and you will continue writing all work in Quarto.