Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
We will be using data from the latest TidyTuesday on polling places in the U.S.
To follow along with the exercises, please be sure that you:
|>
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
Quarto® is an
open-source
scientific and technical
publishing system
built on Pandoc.
Can we reimplement R Markdown such that it’s not tied to R?
Quarto can create various types of documents, including:
Ultimately, it’s up to you!
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
You can use Quarto in RStudio, VS Code, Jupyter, Neovim, and other text editors.
Today, we will use RStudio, which comes bundled with Quarto.
Create a new Quarto document by going to File > New File > Quarto Document.
.qmd
extension of the Quarto documentThis is what the default Quarto document looks like:
key: value
{}
#|
at the beginning of the lineUse the Render button to preview documents as you edit them.
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
embed-resources: true
is very imporant to create self-contained HTML filesexecute
#|
Next, we can create a rough draft of the report by adding:
`r`
Manual:
* Total number of counties: **65**
* Total number of polling places: **2075**
* Election Day: **2020-11-03**
Inline code:
* Total number of counties: **`{{r}} polling_places |> filter(state == "Alabama") |> distinct(county_name) |> count()`**
* Total number of polling places: **`{{r}} polling_places |> filter(state == "Alabama") |> count()`**
* Election Day: **`{{r}} polling_places |> filter(state == "Alabama") |> pull(election_date) |> unique()`**
[^1]
within the text, and [^1]: Here is the footnote.
to write out the footnote.In this report, we present a detailed overview of polling places in various counties across the United States, providing information on the total number of polling places and showcasing example locations for each county on election day.[^1]
[^1]: Data from https://github.com/rfordatascience/tidytuesday
Please open 01-rough-draft.qmd
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
knitr::knit_child()
knitr::knit_child()
allows you to break your content into smaller, modular pieces```{r}
#| results: hide
counties <- polling_places |> filter(state == "Alabama") |> distinct(county_name) |> pull()
expanded_child <- counties |>
map(function(county) knitr::knit_expand("../_template.qmd", current_county = county)) |>
flatten()
parsed_child <- knitr::knit_child(text = unlist(expanded_child))
```
`{{r}} parsed_child`
In another file called _template.qmd
:
```{r}
### {{current_county}} COUNTY
* Total Polling Places: `{{r}} polling_places |> filter(state == params$state, county_name == "{{current_county}}") |> count()`
* Example Locations:
```{r}
polling_places |>
filter(state == params$state,
county_name == "{{current_county}}") |>
head(6) |>
select(name, address.x) |>
kbl(format = "markdown")
```
Please open 02-iterate-report-knit-child.qmd
Source: Parameterized Reporting with Quarto by Jadey Ryan
params
in the key:value pairparams$state
notation anytime there’s a hardcoded valueparams$state
notation anytime there’s a hardcoded value```{r}
ggplot(us_states |> filter(NAME == params$state)) +
geom_sf() +
geom_point(data = polling_places |> filter(state == params$state),
aes(x = longitude,
y = latitude),
alpha = 0.4) +
theme_void()
```
Note
This includes our inline code and child _template.qmd
document!
params
in the YAML to rerender the report for different statesquarto render polling-places-report.qmd -P state:'California'
quarto::quarto_render()
Please open 03-iterate-report-parameters.qmd
Option 1:
params
for each state and render the documentOne HTML report for each state.
quarto::quarto_render()
output_format
: file type (html, revealjs, pdf, docx, etc.)output_file
: file name with extensionexecute_params
: named list of parameterspurrr::pwalk(dataframe, quarto_render, quarto_render_args)
```{r}
library(readr)
library(dplyr)
library(quarto)
polling_places <-
readr::read_csv(here::here("data", "geocoded_polling_places.csv"))
polling_places_reports <-
polling_places |>
dplyr::distinct(state) |>
dplyr::slice_head(n = 5) |>
dplyr::mutate(
output_format = "html",
output_file = paste0(
tolower(state),
"-polling-places.html"),
execute_params = purrr::map(
state,
\(state) list(state = state))) |>
dplyr::select(output_file, execute_params)
```
03-iterate-report-parameters.qmd
_parameters-render.R
Note
Jadey Ryan is holding a workshop on parameterized report generation using Quarto with R-Ladies Abuja on February 21st!
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
theme
under html
Please open 04-united-theme.qmd
sketchy quarto
extensionPlease open 05-sketchy-theme.qmd
.css
or .scss
(Syntactically Awesome Style Sheets) file to your project/*-- scss:defaults --*/
@import url('https://fonts.googleapis.com/css2?family=Fraunces:opsz@9..144&family=Gilda+Display&display=swap');
$font-family-sans-serif: "Fraunces", sans-serif;
$presentation-heading-color: #446571;
$code-block-font-size: 0.6em;
$code-color: #5f5f5f;
$presentation-h2-font-size: 1.4em;
$link-color: #446571 !default;
title-block-banner
Please open 06-custom-theme.qmd
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
pdf
to the YAML to render both HTML and PDF versions of the reportPlease open 07-multiple-formats.qmd
Overview
What is Quarto?
Getting started with Quarto
Creating your Quarto report
Iterating your reports
Styling your reports
Rendering other formats
Thank you!
I hope that you enjoyed getting started with reporting using Quarto! I’d love to see what you create:
https://github.com/ivelasq/getting-started-with-report-writing-using-quarto