├── .gitignore
├── .nojekyll
├── 1-welcome
├── 1-welcome.qmd
├── images
│ ├── bulk-density.jpg
│ ├── cascadia-logo.png
│ ├── lydia-gibson.jpeg
│ ├── mts.webp
│ ├── rangeland.jpg
│ └── soil-sampling.jpg
└── index.qmd
├── 2-parameters
├── 2-parameters.qmd
├── images
│ ├── driver-quality.png
│ ├── find-replace-hard-coded-values.png
│ ├── ocean-floor.png
│ ├── snowshoe-graph.png
│ ├── soils-report-html.png
│ ├── template1.png
│ ├── template2.png
│ ├── template3.png
│ └── urban-institute.png
└── index.qmd
├── 3-render
├── 3-render.qmd
├── images
│ ├── other-formats.png
│ └── render-button.png
└── index.qmd
├── 4-conditionals
├── 4-conditionals.qmd
└── index.qmd
├── 5-style
├── 5-style.qmd
├── images
│ ├── browser-tools-modified.png
│ └── browser-tools.png
└── index.qmd
├── 6-summary
├── 6-summary.qmd
├── images
│ └── mts.jpg
└── index.qmd
├── README.md
├── _extensions
└── quarto-ext
│ └── fontawesome
│ ├── _extension.yml
│ ├── assets
│ ├── css
│ │ ├── all.css
│ │ └── latex-fontsize.css
│ └── webfonts
│ │ ├── FontAwesome6Brands-Regular-400.ttf
│ │ ├── FontAwesome6Brands-Regular-400.woff2
│ │ ├── FontAwesome6Free-Regular-400.ttf
│ │ ├── FontAwesome6Free-Regular-400.woff2
│ │ ├── FontAwesome6Free-Solid-900.ttf
│ │ ├── FontAwesome6Free-Solid-900.woff2
│ │ ├── fa-brands-400.ttf
│ │ ├── fa-brands-400.woff2
│ │ ├── fa-regular-400.ttf
│ │ ├── fa-regular-400.woff2
│ │ ├── fa-solid-900.ttf
│ │ ├── fa-solid-900.woff2
│ │ ├── fa-v4compatibility.ttf
│ │ └── fa-v4compatibility.woff2
│ └── fontawesome.lua
├── _freeze
├── 1-welcome
│ └── 1-welcome
│ │ └── execute-results
│ │ └── html.json
├── 2-parameters
│ └── 2-parameters
│ │ └── execute-results
│ │ └── html.json
├── 3-render
│ └── 3-render
│ │ └── execute-results
│ │ └── html.json
├── 4-conditionals
│ └── 4-conditionals
│ │ └── execute-results
│ │ └── html.json
├── 5-style
│ └── 5-style
│ │ └── execute-results
│ │ └── html.json
├── 6-summary
│ └── 6-summary
│ │ └── execute-results
│ │ └── html.json
├── prework
│ └── execute-results
│ │ └── html.json
└── site_libs
│ ├── clipboard
│ └── clipboard.min.js
│ ├── countdown-0.4.0
│ ├── countdown.css
│ ├── countdown.js
│ └── smb_stage_clear.mp3
│ └── revealjs
│ ├── dist
│ ├── reset.css
│ ├── reveal.css
│ ├── reveal.esm.js
│ ├── reveal.esm.js.map
│ ├── reveal.js
│ ├── reveal.js.map
│ └── theme
│ │ ├── fonts
│ │ ├── league-gothic
│ │ │ ├── LICENSE
│ │ │ ├── league-gothic.css
│ │ │ ├── league-gothic.eot
│ │ │ ├── league-gothic.ttf
│ │ │ └── league-gothic.woff
│ │ └── source-sans-pro
│ │ │ ├── LICENSE
│ │ │ ├── source-sans-pro-italic.eot
│ │ │ ├── source-sans-pro-italic.ttf
│ │ │ ├── source-sans-pro-italic.woff
│ │ │ ├── source-sans-pro-regular.eot
│ │ │ ├── source-sans-pro-regular.ttf
│ │ │ ├── source-sans-pro-regular.woff
│ │ │ ├── source-sans-pro-semibold.eot
│ │ │ ├── source-sans-pro-semibold.ttf
│ │ │ ├── source-sans-pro-semibold.woff
│ │ │ ├── source-sans-pro-semibolditalic.eot
│ │ │ ├── source-sans-pro-semibolditalic.ttf
│ │ │ ├── source-sans-pro-semibolditalic.woff
│ │ │ └── source-sans-pro.css
│ │ └── quarto.css
│ └── plugin
│ ├── highlight
│ ├── highlight.esm.js
│ ├── highlight.js
│ ├── monokai.css
│ ├── plugin.js
│ └── zenburn.css
│ ├── markdown
│ ├── markdown.esm.js
│ ├── markdown.js
│ └── plugin.js
│ ├── math
│ ├── katex.js
│ ├── math.esm.js
│ ├── math.js
│ ├── mathjax2.js
│ ├── mathjax3.js
│ └── plugin.js
│ ├── notes
│ ├── notes.esm.js
│ ├── notes.js
│ ├── plugin.js
│ └── speaker-view.html
│ ├── pdf-export
│ ├── pdfexport.js
│ └── plugin.yml
│ ├── quarto-line-highlight
│ ├── line-highlight.css
│ ├── line-highlight.js
│ └── plugin.yml
│ ├── quarto-support
│ ├── footer.css
│ ├── plugin.yml
│ └── support.js
│ ├── reveal-menu
│ ├── menu.css
│ ├── menu.js
│ ├── plugin.yml
│ ├── quarto-menu.css
│ └── quarto-menu.js
│ ├── search
│ ├── plugin.js
│ ├── search.esm.js
│ └── search.js
│ └── zoom
│ ├── plugin.js
│ ├── zoom.esm.js
│ └── zoom.js
├── _publish.yml
├── _quarto.yml
├── data
├── data.R
├── pet-reports.RDS
└── pets.RDS
├── exercises
└── intermediate-exercises.zip
├── images
├── cascadia-jr-quarto.webp
├── jadey.jpg
├── jr-logo-circle.webp
└── jr-logo-quarto.webp
├── index.qmd
├── license.qmd
├── parameterized-quarto-workshop.Rproj
├── prework.qmd
├── slides.scss
└── theme.scss
/.gitignore:
--------------------------------------------------------------------------------
1 | .Rproj.user
2 | .Rhistory
3 | .RData
4 | .Ruserdata
5 | .DS_Store
6 | /.quarto/
7 | _site/
8 | docs/
9 | .html
10 |
--------------------------------------------------------------------------------
/.nojekyll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/.nojekyll
--------------------------------------------------------------------------------
/1-welcome/1-welcome.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Welcome! {width=5em}"
3 | format: revealjs
4 | ---
5 |
6 | ## While waiting for us to begin...
7 |
8 | Open the workshop website and make sure you've completed the pre-work
9 | and have the required software, packages, and exercises.
10 |
11 | [**jadeyryan.quarto.pub/cascadia-quarto/prework**](https://jadeyryan.quarto.pub/cascadia-quarto/prework).
12 |
13 | ```{r}
14 | #| eval: false
15 |
16 | usethis::use_course(
17 | "https://github.com/jadeynryan/parameterized-quarto-workshop/raw/cascadia/exercises/intermediate-exercises.zip"
18 | # , destdir = "C:/Users/jryan/Documents/R/projects"
19 | )
20 |
21 | install.packages(c("dplyr", "fs", "ggplot2", "here", "janitor", "knitr", "lubridate",
22 | "plotly", "purrr", "quarto", "readr", "rmarkdown", "stringr", "tidyr"))
23 | ```
24 |
25 | If `use_course()` didn't work, manually download the zip file from
26 | GitHub:
27 | [github.com/jadeynryan/parameterized-quarto-workshop/tree/cascadia/exercises](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/cascadia/exercises).
28 |
29 | ::: callout-tip
30 | ## Backup option: Posit Cloud
31 |
32 | Join the Posit Cloud [Quarto Cascadia
33 | workspace](https://posit.cloud/spaces/519059/join?access_code=ckv18LHEcSw3QtQ904uvpzLVlh4L2rk6RhKdpwyp)
34 | and open the [Intermediate Exercises
35 | project](https://posit.cloud/spaces/519059/content/8351107).
36 | :::
37 |
38 | ## Acknowledgements
39 |
40 | {.center fig-alt="Cascadia R Conf logo"
41 | height="350px"}
42 |
43 | \
44 |
45 | **Workshop structure adapted from:**
46 |
47 | [R/Medicine Data Cleaning 2023
48 | Workshop](https://shannonpileggi.github.io/rmedicine-data-cleaning-2023/)
49 | taught by [Crystal Lewis](https://cghlewis.com/), [Shannon
50 | Pileggi](https://www.pipinghotdata.com/), and [Peter
51 | Higgins](https://bookdown.org/pdr_higgins/rmrwr/)
52 |
53 | \
54 |
55 | [ASA Traveling Courses on
56 | Quarto](https://quarto.org/docs/blog/posts/2023-12-05-asa-traveling-courses/)
57 | taught by [Mine Çetinkaya-Rundel](https://mine-cr.com/) and [Andrew
58 | Bray](https://andrewpbray.github.io/)
59 |
60 | ## Code of Conduct
61 |
62 | Please review and abide by:
63 | [cascadiarconf.com/policies/](https://cascadiarconf.com/policies/)
64 |
65 | \
66 |
67 | 💙 Treat everyone with respect and kindness.
68 |
69 | \
70 |
71 | 💜 Everyone should feel welcome and safe.
72 |
73 | ## Disclaimer and license
74 |
75 | Opinions expressed are solely my own and do not express the views of my
76 | employer or any organizations I am associated with.
77 |
78 | \
79 |
80 | This work is licensed under [Creative Commons
81 | Attribution-NonCommercial-ShareAlike 4.0 International (CC
82 | BY-NC-SA)](https://creativecommons.org/licenses/by-nc-sa/4.0/).
83 |
84 | {{< fa brands creative-commons size=2x >}} {{< fa brands creative-commons-by size=2x >}} {{< fa brands creative-commons-nc size=2x >}} {{< fa brands creative-commons-sa size=2x >}}
85 |
86 |
87 | ## Meet Jadey Ryan
88 |
89 | ::: columns
90 | ::: {.column width="44%"}
91 | Data scientist at WA Dept of Agriculture
92 |
93 | The Coding Cats: cat & code themed merch
94 |
95 | {{< fa link size=xl >}} [jadeyryan.com](https://jadeyryan.com)
96 |
97 | {{< fa brands mastodon size=xl >}} [\@jadeynryan](https://fosstodon.org/@jadeynryan)
98 |
99 | {{< fa brands linkedin size=xl >}} [linkedin.com/in/jadey-ryan](https://www.linkedin.com/in/jadey-ryan)
100 |
101 | {{< fa brands github size=xl >}} [jadeynryan](https://github.com/jadeynryan/)
102 |
103 | {{< fa brands etsy size=xl >}} [thecodingcats.etsy.com](https://thecodingcats.etsy.com/)
104 |
105 | {fig-alt="Three snowshoe siamese cats in loaf mode. From left to right: Tai, Mai, and Skye" style="border-radius:1em;margin-top:auto"}
106 | :::
107 |
108 | ::: {.column width="28%"}
109 | {fig-alt="Jadey collecting a bulk density soil sample in a field of wheat stubble." style="border-radius:1em;margin-top:auto"}
110 | :::
111 |
112 | ::: {.column width="28%"}
113 | ::: {layout-nrow="2"}
114 | {style="border-radius:1em;margin-top:auto"
115 | fig-alt="Jadey standing in a field of wheat stubble holding a 3 foot long soil sampling probe over her shoulder."}
116 |
117 | {fig-alt="Jadey standing in a grazed wildflower meadow with two colleagues collecting soil samples."
118 | style="border-radius:1em;margin-top:auto"}
119 | :::
120 |
121 | {{< fa camera title="Photo credit" >}} [@leslie.mmichel](https://twitter.com/leslie_mmichel)
122 | :::
123 | :::
124 |
125 | ## Meet our TA: Lydia Gibson
126 |
127 | {.center fig-alt="Photo of Lydia Gibson" style="border-radius:1em;"}
128 |
129 | ## Learning objectives
130 |
131 | ::: incremental
132 | - Understand what parameterized reporting is and when it is useful.
133 | - Convert a Quarto document into a parameterized template and render
134 | all variations.
135 | - Generate multiple format outputs from the same template using:
136 | - conditional content
137 | - conditional code execution, and
138 | - custom styling.
139 | :::
140 |
141 | ## Schedule
142 |
143 | | Time | Topic |
144 | |-------------|------------------------------------------------------|
145 | | 1:30 - 2:00 | Welcome & [Parameterizing reports](../2-parameters/) |
146 | | 2:00 - 3:00 | [Rendering reports](../3-render/) |
147 | | 3:00 - 3:30 | Break |
148 | | 3:30 - 4:00 | [Conditional content & code](../4-conditionals/) |
149 | | 4:00 - 4:20 | [Styling reports](../5-styling/) |
150 | | 4:20 - 4:30 | [Summary](../6-summary/) |
151 |
152 | ## Workshop structure
153 |
154 | Presentation
155 |
156 | 💃🏻 Demos
157 |
158 | 💪🏻 Exercises
159 |
160 | \
161 |
162 | . . .
163 |
164 | Let us know how you're doing by displaying your stickies!
165 |
166 | 🟦 I'm all good; I'm done.
167 |
168 | 🟧 I'm a little lost; I could use some help.
169 |
170 | # 💪🏼 Exercise {.exercise}
171 |
172 | **Meet your neighbors**:
173 |
174 | - Your name
175 |
176 | - Your favorite snack 🍎🧀🍦🍫🍿
177 |
178 | - What kinds of reports are you wanting to create after today's
179 | workshop?
180 |
181 | ```{r}
182 | #| echo: false
183 | countdown::countdown(minutes = 5, top = 0)
184 | ```
185 |
--------------------------------------------------------------------------------
/1-welcome/images/bulk-density.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/bulk-density.jpg
--------------------------------------------------------------------------------
/1-welcome/images/cascadia-logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/cascadia-logo.png
--------------------------------------------------------------------------------
/1-welcome/images/lydia-gibson.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/lydia-gibson.jpeg
--------------------------------------------------------------------------------
/1-welcome/images/mts.webp:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/mts.webp
--------------------------------------------------------------------------------
/1-welcome/images/rangeland.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/rangeland.jpg
--------------------------------------------------------------------------------
/1-welcome/images/soil-sampling.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/1-welcome/images/soil-sampling.jpg
--------------------------------------------------------------------------------
/1-welcome/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Welcome"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](1-welcome.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/2-parameters/2-parameters.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Parameterizing reports {width=5em}"
3 | format: revealjs
4 | ---
5 |
6 | ## Examples of parameterized reports
7 |
8 | ::: columns
9 | ::: {.column width="25%"}
10 | {.lightbox group="examples"
11 | fig-alt="RStudio R Markdown parameterized report project for mapping ocean floors."}
12 |
13 | [Ocean floor maps](https://rmarkdown.rstudio.com/lesson-6.html)
14 | :::
15 |
16 | ::: {.column width="25%"}
17 | {.lightbox group="examples"
18 | fig-alt="Report for Alabama spending with text and plots generated from parameterized R Markdown."}
19 |
20 | [Fiscal
21 | briefs](https://book.rwithoutstatistics.com/parameterized-reports-chapter.html)
22 | :::
23 |
24 | ::: {.column width="25%"}
25 | {.lightbox group="examples"
26 | fig-alt="Report for Alaska driver quality with text, plot, and table generated from parameterized RMarkdown."}
27 |
28 | [Bad
29 | drivers](https://urban-institute.medium.com/iterated-fact-sheets-with-r-markdown-d685eb4eafce)
30 | :::
31 |
32 | ::: {.column width="25%"}
33 | {.lightbox group="examples"
34 | fig-alt="HTML report for soil health survey participant, generated from a parameterized Quarto report."}
35 |
36 | [Soil health](https://wa-department-of-agriculture.github.io/soils/)
37 | :::
38 | :::
39 |
40 | . . .
41 |
42 | \
43 |
44 | **Another use case: different audiences, different reports**
45 |
46 | Show code for technical staff and hide code for everyone else ([StackOverflow
47 | example](https://stackoverflow.com/questions/73571919/how-to-pass-logical-parameters-with-the-quarto-r-package-to-the-knitr-chunk-opti)).
48 |
49 | ## Like a custom function
50 |
51 | ::: r-stack
52 | {.fragment
53 | fig-alt="File with the word '.qmd' inside and the word 'Function' above."
54 | width="1300" fig-align="left" style="margin-top:-1em"}
55 |
56 | {.fragment
57 | fig-alt="An arrow points from 'Input' with 'params$year' to the previous image with 'Function' and '.qmd' file."
58 | width="1300" fig-align="left" style="margin-top:-1em"}
59 |
60 | {.fragment
61 | fig-alt="In addition to the previous two images, arrows point to five reports with years 2019 through 2023 on them in a flow chart."
62 | width="1300" fig-align="left" style="margin-top:-1em"}
63 | :::
64 |
65 | ## What makes a report "parameterized"?
66 |
67 | - YAML header with `params` key-value pairs
68 |
69 | - Use these `params` to create different variations of a report from a single `.qmd` document.
70 |
71 | . . .
72 |
73 | ::: callout-important
74 | - Valid parameter values are strings, numbers, or Boolean.
75 |
76 | - Must serialize a dataframe to pass it as a parameter, then un-serialize it
77 | back to a dataframe within the `.qmd` content.
78 |
79 | - See [Christophe Dervieux's answer in Posit
80 | Community](https://community.rstudio.com/t/param-converted-from-data-frame-to-list/155556/9)
81 | to understand why.
82 |
83 | - See [John Paul Helveston's blog
84 | post](https://www.jhelvy.com/posts/2023-02-28-parameterized-pdfs-with-quarto/#passing-data-frames-as-parameters)
85 | to learn how to use {jsonlite} as a workaround.
86 | :::
87 |
88 | ## Workflow
89 |
90 | ::: incremental
91 | 1. Write report template with default values hard-coded, and then render & review.
92 |
93 | 2. Set default `params` key-value pairs in YAML.
94 |
95 | 3. Replace hard-coded values with the `params` variables.
96 |
97 | 4. Render the single report and review.
98 |
99 | 5. Render extreme cases and review.
100 |
101 | - Parameter values with barely any data and with tons of data.
102 |
103 | 6. Render all variations of the report at once.
104 | :::
105 |
106 | # 💪🏼 Exercise {.exercise}
107 |
108 | **Explore a report without parameters and see where we could add them.**
109 |
110 | 1. Open `1-swiss-cats.qmd`.
111 |
112 | 2. Click the
113 | {fig-alt="Quarto render button in RStudio" style="vertical-align:middle;" width="49"} **Render** button.
114 |
115 | 3. Look at the source markdown & code and the rendered report.
116 |
117 | 4. 💬 **Chat**: What variables could we set as parameters?
118 |
119 | 💡 **Hint**: run the `setup` chunk and look at the `pets` dataframe to see
120 | what variables it has.
121 |
122 | ```{r}
123 | #| echo: false
124 | countdown::countdown(minutes = 5, top = 0)
125 | ```
126 |
127 | ## Set `params` in YAML header
128 |
129 | ```{.yaml code-line-numbers="|2|3,4,6|5|7-8|11"}
130 | ---
131 | title: "Swiss Cats" # Metadata
132 | format: # Set format types
133 | html:
134 | toc: true # Set additional options
135 | docx: default
136 | params: # Set default parameter key-value pairs
137 | fave_breed: "Snowshoe"
138 | ---
139 |
140 | Report content goes here. # Write narrative and code
141 | ```
142 |
143 | . . .
144 |
145 | ::: callout-important
146 | Your default `params` key-value pairs must be found in your dataset. Otherwise, code will error or output will be blank.
147 |
148 | The variable name for `params` can be anything you choose. Often, it's a column name in your dataset.
149 | :::
150 |
151 | ## Access `params`
152 |
153 | ```{r}
154 | #| include: false
155 |
156 | # Set params for slide
157 | params <- list(
158 | fave_breed = "Snowshoe"
159 | )
160 | ```
161 |
162 | Run any line or chunk to add `params` to your environment.
163 |
164 | . . .
165 |
166 | `params` object is a list.
167 |
168 | ```{r}
169 | str(params)
170 | ```
171 |
172 | \
173 |
174 | . . .
175 |
176 | Access with `$` notation.
177 |
178 | ```{r}
179 | params$fave_breed
180 | ```
181 |
182 | \
183 |
184 | . . .
185 |
186 | For inline code in YAML or report content, enclose the expression in `` `r ` ``.
187 |
188 | ```markdown
189 | My favorite cat breed is the **``r I("r params$fave_breed")``**.
190 | ```
191 |
192 | My favorite cat breed is the **`r params$fave_breed`**.
193 |
194 | ## Replace hard-coded values with `params`
195 |
196 | `Cmd`/`Ctrl` + `F` to find where to replace hard-coded values with `params`.
197 |
198 | {fig-alt="Find and replace toolbar with "pet_type in the Search field highlighted by a purple box and "params$pet_type in the Replace field highlighted by a blue box. The .qmd file shows a filter statement with the "pet_type highlighted by RStudio as a match for the Find tool. This filter statement is highlighted by a purple box with an arrow pointing to a blue box that has the filter statement with the hard-coded "cats string replaced with "params$pet_type."}
199 |
200 | ## Replace hard-coded values with `params`
201 |
202 | **Use `$` list notation in code** for plot/table titles and labels, filtering, etc.
203 |
204 | \
205 |
206 | `paste()` syntax:
207 |
208 | ```{r}
209 | #| eval: false
210 |
211 | # ggplot2 code +
212 | labs(title = paste(params$fave_breed, "population"))
213 | ```
214 |
215 | . . .
216 |
217 | \
218 |
219 | `glue::glue()` syntax:
220 |
221 | ```{r}
222 | #| eval: false
223 |
224 | # ggplot2 code +
225 | labs(title = glue::glue("{params$fave_breed} population"))
226 | ```
227 |
228 | \
229 |
230 | . . .
231 |
232 | **Use inline R code** for markdown.
233 |
234 | ```markdown
235 | ## My favorite breed: **``r I("r params$fave_breed")``**.
236 | ```
237 |
238 | ##
239 |
240 | {fig-align="center"}
241 |
242 | # 💃🏻 Demo {.demo}
243 |
244 | Modify `1-swiss-cats-demo.qmd` to add `pet_type` and `fave_breed` parameters.
245 |
246 | \
247 |
248 | This parameterized version of `1-swiss-cats.qmd` is the starting point for the next section's exercises (`2-quarto-render.qmd`).
249 |
--------------------------------------------------------------------------------
/2-parameters/images/driver-quality.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/driver-quality.png
--------------------------------------------------------------------------------
/2-parameters/images/find-replace-hard-coded-values.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/find-replace-hard-coded-values.png
--------------------------------------------------------------------------------
/2-parameters/images/ocean-floor.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/ocean-floor.png
--------------------------------------------------------------------------------
/2-parameters/images/snowshoe-graph.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/snowshoe-graph.png
--------------------------------------------------------------------------------
/2-parameters/images/soils-report-html.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/soils-report-html.png
--------------------------------------------------------------------------------
/2-parameters/images/template1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/template1.png
--------------------------------------------------------------------------------
/2-parameters/images/template2.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/template2.png
--------------------------------------------------------------------------------
/2-parameters/images/template3.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/template3.png
--------------------------------------------------------------------------------
/2-parameters/images/urban-institute.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/2-parameters/images/urban-institute.png
--------------------------------------------------------------------------------
/2-parameters/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Parameterizing reports"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](2-parameters.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/3-render/3-render.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Rendering reports {width=5em}"
3 | format: revealjs
4 | ---
5 |
6 | ## Three ways to render
7 |
8 | ::: incremental
9 | 1. **RStudio/Quarto integration**:
10 |
11 | {fig-alt="Quarto render button in RStudio" style="vertical-align:middle;" width="49"} **Render** button in RStudio or `Cmd`/`Ctrl` + `Shift` + `K` keyboard shortcut
12 |
13 | 2. ✨ **Quarto R package** ✨
14 |
15 | ```{.r filename="Console or R script"}
16 | quarto::quarto_render(
17 | input = here::here("2-quarto-render.qmd"), # Input Quarto file
18 | execute_params = list( # Named list of params
19 | pet_type = "cats",
20 | fave_breed = "Snowshoe"))
21 | ```
22 |
23 | 3. **Quarto CLI**
24 |
25 | ```{.bash filename="Terminal"}
26 | quarto render 2-quarto-render.qmd -P pet_type:'cats' -P fave_breed:'Snowshoe'
27 | ```
28 |
29 | :::
30 |
31 | # 💪🏼 Exercise {.exercise}
32 |
33 | **Change parameters in the YAML and render using {fig-alt="Quarto render button in RStudio" style="vertical-align:middle;" width="49"} Render button.**
34 |
35 | 1. Look at the unique pet breeds and pick your favorite.
36 | ```{.r}
37 | # Run in the console
38 | pets <- readr::read_rds(here::here("data", "pets.RDS")) |>
39 | dplyr::distinct(pet_type, breed) |> View()
40 | ```
41 |
42 | 2. In `2-quarto-render.qmd`, change the default parameters in the YAML to your favorite pet type and breed. Render using the {fig-alt="Quarto render button in RStudio" style="vertical-align:middle;" width="49"} **Render** button.
43 |
44 | ```{.yaml}
45 | params:
46 | pet_type: "___"
47 | fave_breed: "___"
48 | ```
49 |
50 | 3. 💬 **Chat**: Which breed did you pick and why? What do you think will happen if you set the `pet_type` default parameter to "cats" and the `fave_breed` parameter to "American Bulldog"?
51 |
52 | Try it out and discuss what happend!
53 |
54 | ```{r}
55 | #| echo: false
56 | countdown::countdown(minutes = 7, top = 0)
57 | ```
58 |
59 | # 💪🏼 Exercise {.exercise}
60 |
61 | **Change parameters and render using `quarto_render()`.**
62 |
63 | 1. Render with `quarto::quarto_render()`.
64 |
65 | ```r
66 | # Run in the console
67 | quarto::quarto_render(
68 | input = here::here("2-quarto-render.qmd"),
69 | execute_params = list(
70 | pet_type = "___",
71 | fave_breed = "___"))
72 | ```
73 |
74 | 2. 💬 **Chat**: What kinds of variables will you use as parameters for your reports?
75 |
76 | ```{r}
77 | #| echo: false
78 | countdown::countdown(minutes = 7, top = 0)
79 | ```
80 |
81 | ## Render all 538 reports
82 |
83 | One HTML report for each cat breed and each dog breed.
84 |
85 | :::: panel-tabset
86 |
87 | ## 📊 Data
88 |
89 | ```{r}
90 | pets <- readr::read_rds(here::here("data", "pets.RDS"))
91 |
92 | pets |>
93 | dplyr::distinct(pet_type, breed) |>
94 | dplyr::count(pet_type) |>
95 | janitor::adorn_totals()
96 | ```
97 |
98 | ## 👷🏼♂️ Manual 1
99 |
100 | 1. Change the default `params` in the YAML.
101 |
102 | 2. **Render** button or `Cmd`/`Ctrl` + `Shift` + `K` keyboard shortcut.
103 |
104 | 3. Rename the rendered report to include the parameter & prevent overwriting.
105 |
106 | 4. Repeat 537 times.
107 |
108 | 😭
109 |
110 | ## 👷🏻♀️ Manual 2
111 |
112 | ```{r}
113 | #| eval: false
114 | quarto::quarto_render(
115 | input = here::here("2-quarto-render.qmd"),
116 | output_file = "dogs-affenpinscher-report.html",
117 | execute_params = list(
118 | pet_type = "dogs",
119 | fave_breed = "Affenpinscher"))
120 |
121 | quarto::quarto_render(
122 | input = here::here("2-quarto-render.qmd"),
123 | output_file = "dogs-afghan-hound-report.html",
124 | execute_params = list(
125 | pet_type = "dogs",
126 | fave_breed = "Afghan Hound"))
127 |
128 | quarto::quarto_render(
129 | input = here::here("2-quarto-render.qmd"),
130 | output_file = "dogs-aidi-chien-de-montagne-de-l-atlas-report.html",
131 | execute_params = list(
132 | pet_type = "dogs",
133 | fave_breed = "Aidi Chien De Montagne De L Atlas"))
134 |
135 | quarto::quarto_render(
136 | input = here::here("2-quarto-render.qmd"),
137 | output_file = "dogs-akita-report.html",
138 | execute_params = list(
139 | pet_type = "dogs",
140 | fave_breed = "Akita"))
141 |
142 | # + 534 more times...
143 | # 😭
144 | ```
145 |
146 | ## ⚡ Programatically
147 |
148 | **Create a dataframe with three columns that match `quarto_render()` args:**
149 |
150 | - `output_format`: file type (html, revealjs, pdf, docx, etc.)
151 |
152 | - `output_file`: file name with extension
153 |
154 | - `execute_params`: named list of parameters
155 |
156 | **Map over each row:**
157 |
158 | - `purrr::pwalk(dataframe, quarto_render, )` 😎
159 | ::::
160 |
161 | ## Primer on `purrr` functions for iteration
162 |
163 | :::: {.columns}
164 |
165 | ::: {.column width="60%"}
166 | **Map functions** apply the same action/function to each element of an object.
167 |
168 | - Base R `apply()` functions are map functions.
169 |
170 | - `purrr` map functions have consistent syntax and the output data type is predictable.
171 |
172 | `for loops` → `lapply()` → `purrr::map()`
173 | :::
174 |
175 | ::: {.column width="5%"}
176 | :::
177 |
178 | ::: {.column width="35%"}
179 | {fig-alt="purrr R package logo"}
180 | :::
181 | ::::
182 |
183 | . . .
184 |
185 | **Learn more**:
186 |
187 | - [Iteration chapter of *R for Data Science*](https://r4ds.had.co.nz/iteration.html)
188 |
189 | - R-Ladies Baltimore presentation [*Make your R Code purr with `purrr`*](https://www.youtube.com/watch?v=IewsPpjKElc)
190 |
191 | - Jenny Bryan's [tutorial](https://jennybc.github.io/purrr-tutorial/) and [workshop](https://github.com/jennybc/row-oriented-workflows)
192 |
193 | ## Create dataframe to iterate over
194 |
195 | ```{r}
196 | #| code-line-numbers: "|2|4|5-9|11-14|"
197 | pet_reports <- pets |>
198 | dplyr::distinct(pet_type, breed) |> # Get distinct pet/breed combos
199 | dplyr::mutate(
200 | output_format = "html", # Make output_format column
201 | output_file = paste( # Make output_file column:
202 | tolower(pet_type), # cats-abyssiniane-report.html
203 | tolower(gsub(" ", "-", breed)),
204 | "report.html",
205 | sep = "-"
206 | ),
207 | execute_params = purrr::map2( # Make execute_params column
208 | pet_type,
209 | breed,
210 | \(pet_type, breed) list(pet_type = pet_type, breed = breed)))
211 | ```
212 |
213 | ```{r}
214 | #| echo: false
215 | saveRDS(pet_reports, "../data/pet-reports.RDS")
216 | ```
217 |
218 | ## Subset to first 2 cat/dog breeds
219 |
220 | ```{r}
221 | pet_reports_subset <- pet_reports |>
222 | dplyr::slice_head(n = 2, by = pet_type) |>
223 | dplyr::select(output_file, execute_params)
224 |
225 | pet_reports_subset
226 | ```
227 |
228 | ## Map over each row
229 |
230 | ::: incremental
231 | - `purrr::pwalk()` iterates over multiple arguments simultaneously.
232 |
233 | - First `.l` argument is a *list of vectors*.
234 |
235 | - Dataframe is a special case of `.l` that iterates over rows.
236 | :::
237 | . . .
238 |
239 | ```{r}
240 | #| eval: false
241 | #| code-line-numbers: "|2|3|4|5|"
242 |
243 | purrr::pwalk(
244 | .l = pet_reports_subset, # Dataframe to map over
245 | .f = quarto::quarto_render, # Function we are applying to each row
246 | input = here::here("2-quarto-render.qmd"), # Named arguments of .f
247 | .progress = TRUE # Show a progress bar :)
248 | )
249 | ```
250 |
251 | . . .
252 |
253 | ::: callout-note
254 | `input` is the only named argument of `quarto_render()` included in `pwalk()`.
255 |
256 |
257 | `output_format`, `output_file`, and `execute_params` are already passed in through the dataframe.
258 | :::
259 |
260 | # Multiple formats {.section}
261 |
262 | ## Render all reports to all formats
263 |
264 | Add to the `format:` YAML option to render additional output formats from the same `.qmd` file.
265 |
266 | ``` {.yaml}
267 | ---
268 | format:
269 | html:
270 | embed-resources: true # Makes the report self-contained
271 | pdf: default # If not using any additional format options,
272 | docx: default # set value to `default`
273 | ---
274 | ```
275 |
276 | . . .
277 |
278 | **Note**: the Render button now has a dropdown!
279 |
280 | {width=60% fig-alt="Screenshot of Quarto file with the Render dropdown showing options for HTML, PDF, and MS Word formats."}
281 |
282 | [Quarto docs on multiple formats](https://quarto.org/docs/get-started/authoring/rstudio.html#multiple-formats)
283 |
284 | ## Format links for HTML output
285 |
286 | Links to download the other formats will automatically appear in HTML documents.
287 |
288 | {fig-alt="Screenshot of a HTML page that includes links to the PDF and MS Word formats in the table of contents under the heading Other Formats." style="border-radius:1em"}
289 |
290 | ## Format link options
291 |
292 | **Choose which format links to include:**
293 |
294 | ```{yaml}
295 | #| code-line-numbers: "7"
296 | ---
297 | format:
298 | html:
299 | embed-resources: true
300 | pdf: default
301 | docx: default
302 | format-links: [pdf, docx]
303 | ---
304 | ```
305 |
306 | . . .
307 |
308 | **Or hide all links:**
309 |
310 | ```{yaml}
311 | #| code-line-numbers: "7"
312 | ---
313 | format:
314 | html:
315 | embed-resources: true
316 | pdf: default
317 | docx: default
318 | format-links: false
319 | ---
320 | ```
321 |
322 | # 💃🏻 Demo {.demo}
323 |
324 | Programmatically render all reports in all formats in `3-purrr-render-demo.qmd` and `3-purrr-render-demo.R`.
325 |
326 | \
327 |
328 | 💡 Use these files as a template and modify them for your own projects!
329 |
330 | ## Directory limitations
331 |
332 | ::: incremental
333 |
334 | :::: callout-important
335 | ## Can't render reports to another directory.
336 |
337 | [`output-dir` YAML option](https://quarto.org/docs/books/book-output.html#output-path) only works for *Quarto projects* that contain a `_quarto.yml` config file.
338 |
339 | **Workaround**: use [`{fs}`](https://fs.r-lib.org/) to move files after rendering.
340 |
341 | See `3-purrr-render-demo.R` for example.
342 |
343 | **More info**: [GitHub discussion](https://github.com/quarto-dev/quarto-cli/discussions/2171#discussioncomment-4865286) and [GitHub issue](https://github.com/quarto-dev/quarto-r/issues/81).
344 | ::::
345 |
346 | \
347 |
348 | :::: callout-important
349 | ## Can't embed resources for a Quarto document in a subfolder.
350 |
351 | If using `embed-resources: true` YAML option, `.qmd` can't be in subfolder, otherwise:
352 |
353 | [[WARNING] Could not fetch resource ...]{.warning}
354 |
355 | **More info**: [GitHub discussion](https://github.com/quarto-dev/quarto-cli/discussions/4041#discussioncomment-6052000) and [GitHub issue](https://github.com/quarto-dev/quarto-cli/issues/5765).
356 | ::::
357 | :::
358 |
359 | # 🚶🏻♀ 30-min break 🧘🏾♂️️ {.section}
360 |
361 | ```{r}
362 | #| echo: false
363 | countdown::countdown(minutes = 30, top = 0)
364 | ```
365 |
--------------------------------------------------------------------------------
/3-render/images/other-formats.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/3-render/images/other-formats.png
--------------------------------------------------------------------------------
/3-render/images/render-button.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/3-render/images/render-button.png
--------------------------------------------------------------------------------
/3-render/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Rendering reports"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](3-render.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/4-conditionals/4-conditionals.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Conditional content & code {width=4em}"
3 | format: revealjs
4 | ---
5 |
6 | # Conditional content {.section}
7 |
8 | ## Control content visibility
9 |
10 | Create a div, span, or non-executable code block with one option from each of the below columns:
11 |
12 | `{.class attribute="format"}`
13 |
14 | :::: {.columns}
15 |
16 | ::: {.column width="30%"}
17 | **Class**
18 |
19 | - `.content-visible`
20 | - `.content-hidden`
21 | :::
22 |
23 | ::: {.column width="30%"}
24 | **Attribute**
25 |
26 | - `when-format="___"`
27 | - `unless-format="___"`
28 | :::
29 |
30 | ::: {.column width="30%"}
31 | **Format**
32 |
33 | - `latex` or `pdf`
34 | - `epub`
35 | - `html` or `revealjs`
36 | - `markdown`
37 | :::
38 |
39 | ::::
40 |
41 | :::: {.fragment style="margin-top:-3.5em"}
42 |
43 | **Examples:**
44 |
45 | ::: panel-tabset
46 |
47 | ## Divs
48 |
49 | ```markdown
50 | ::: {.content-visible when-format="html"}
51 |
52 | Will only appear in HTML.
53 |
54 | :::
55 | ```
56 |
57 | ## Spans
58 |
59 | ``` markdown
60 | Some text
61 | [in HTML.]{.content-visible when-format="html"}
62 | [in PDF.]{.content-visible when-format="pdf"}
63 | ```
64 |
65 | ## Non-executable code
66 |
67 | Fenced code blocks purely for documentation.
68 |
69 | ````markdown
70 | ```{.python .content-visible when-format="html"}
71 | # code shown only in HTML
72 | 2 + 2
73 | ```
74 | ````
75 | :::
76 | ::::
77 |
78 | . . .
79 |
80 | [Conditional Quarto docs](https://quarto.org/docs/authoring/conditional.html) & [Format aliases](https://quarto.org/docs/authoring/conditional.html#format-matching)
81 |
82 | ## Useful for static/interactive features
83 |
84 | Pairs well with the `{{< include >}}` shortcode to re-use content without copying/pasting.
85 |
86 | . . .
87 |
88 | ::::: panel-tabset
89 |
90 | ## Static
91 |
92 | ```markdown
93 | :::: {.content-visible unless-format="html"}
94 |
95 | ## Cats
96 |
97 | {{{< include _cats.qmd >}}}
98 |
99 | ## Dogs
100 |
101 | {{{< include _dogs.qmd >}}}
102 |
103 | ::::
104 | ```
105 |
106 | ## Interactive
107 |
108 | ```markdown
109 | :::: {.content-visible when-format="html"}
110 | ::: panel-tabset
111 |
112 | ## Cats
113 |
114 | {{{< include _cats.qmd >}}}
115 |
116 | ## Dogs
117 |
118 | {{{< include _dogs.qmd >}}}
119 |
120 | :::
121 | ::::
122 | ```
123 | :::::
124 |
125 | . . .
126 |
127 | ::: callout-tip
128 | ## Good practice
129 | Use an underscore prefix for included files so they are automatically ignored by a Quarto render of a project ([Include shortcode Quarto docs](https://quarto.org/docs/authoring/includes.html)).
130 | :::
131 |
132 | # 💪🏼 Exercise {.exercise}
133 |
134 | **Use conditional content divs to control when tabsets are shown.**
135 |
136 | 1. Modify `3-conditional-content.qmd` so that the `panel-tabset` is visible for HTML reports and hidden for all other formats.
137 |
138 | \
139 |
140 | 2. Try another way to get the same result.
141 |
142 | `{.content-visible when-format="html"}` is essentially the same as `{.content-hidden unless-format="html"}`.
143 |
144 | \
145 |
146 | 3. 💬 **Chat**: Besides tabsets, what other kinds of content might you want to make visible for only a certain format?
147 |
148 | ```{r}
149 | #| echo: false
150 | countdown::countdown(minutes = 5, top = 0)
151 | ```
152 |
153 | # Conditional code execution {.section}
154 |
155 | ## Conditionally execute a code chunk
156 |
157 | ::: incremental
158 |
159 | - More efficient to not execute code that generates interactive outputs for static reports.
160 |
161 | - Useful for executing interactive plot code (e.g., `plotly` or `ggiraph`) for HTML reports and static `ggplot2` code for all other formats.
162 |
163 | - Useful for executing different code based on a parameter value.
164 |
165 | - Not currently a feature of Quarto v1.4. Follow along with this [GitHub discussion](https://github.com/quarto-dev/quarto-cli/discussions/3260#discussioncomment-4573926).
166 |
167 | - Chunk options can use R code for option values with `!expr`. Learn about the limitations to this YAML "tag" literal syntax in the [Quarto Chunk Options reference](https://quarto.org/docs/computations/r.html#chunk-options).
168 |
169 | :::
170 |
171 | ## Conditional code based on output
172 |
173 | Get the format of the Pandoc output by including the following in the setup chunk of your `.qmd` file:
174 |
175 | ```{r}
176 | #| label: setup
177 | #| echo: fenced
178 |
179 | # Get output format
180 | format <- knitr::opts_knit$get("rmarkdown.pandoc.to")
181 | ```
182 |
183 | ## Use `eval: !expr` chunk option
184 |
185 | ::: panel-tabset
186 |
187 | ## Static plot
188 |
189 | ```markdown
190 | #| echo: fenced
191 | #| eval: !expr format %in% c("latex", "docx")
192 |
193 | # code to create static {ggplot2}
194 | ```
195 |
196 | :::: callout-important
197 | ## Use `latex` not `pdf`
198 |
199 | `format` comes from `knitr::opts_knit$get("rmarkdown.pandoc.to")`. Pandoc uses LaTeX to create PDFs.
200 |
201 | Quarto [format aliases](https://quarto.org/docs/authoring/conditional.html#format-matching) won't work here.
202 | ::::
203 |
204 | ## Interactive plot
205 |
206 | ```markdown
207 | #| echo: fenced
208 | #| eval: !expr format == "html"
209 |
210 | # code to create interactive {plotly}
211 | ```
212 |
213 | :::
214 |
215 | # 💪🏼 Exercise {.exercise}
216 |
217 | **Conditionally execute `ggplot2` code for static reports & `plotly` code for interactive reports.**
218 |
219 | 1. Open `5-conditional-code.qmd`.
220 |
221 | 2. In the `ggplot2` code chunks and `plotly` code chunks, fill in the blanks for the `eval: ` option.
222 |
223 | ```{r}
224 | # Replace ___ with html, latex, or docx.
225 |
226 | #| eval: !expr format == "___"
227 |
228 | #| eval: !expr format %in% c("___", "___")
229 | ```
230 |
231 | 3. 💬 **Chat**: How would you change the `eval: ` option to execute a chunk based on a parameter value rather than the output format?
232 |
233 | ```{r}
234 | #| echo: false
235 | countdown::countdown(minutes = 5, top = 0)
236 | ```
237 |
238 | ## Conditional code based on parameter
239 |
240 | Use `params` in `!expr`:
241 |
242 | ``` r
243 | #| eval: !expr params$fave_breed == "Snowshoe"
244 |
245 | # Code for a special plot for my favorite cat breed.
246 | ```
247 |
248 | \
249 |
250 | . . .
251 |
252 | ``` r
253 | #| eval: !expr !params$fave_breed == "Snowshoe"
254 |
255 | # Code for a different plot for all other breeds.
256 | # Note the ! in front of params.
257 | ```
258 |
--------------------------------------------------------------------------------
/4-conditionals/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Conditional content & code"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](4-conditionals.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/5-style/5-style.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Styling your reports {width=5em}"
3 | format: revealjs
4 | ---
5 |
6 | # HTML {.section}
7 |
8 | ## Bootswatch themes
9 |
10 | Choose from or customize one of 25 [Bootswatch](https://bootswatch.com/) themes.
11 |
12 | \
13 |
14 | . . .
15 |
16 | **Set the theme** in the YAML under the `html` key:
17 |
18 | ``` yaml
19 | format:
20 | html:
21 | theme: flatly
22 | ```
23 |
24 | \
25 |
26 | . . .
27 |
28 | **Customize a theme** by including a custom `.scss` file under the `theme` key:
29 |
30 | ``` yaml
31 | format:
32 | html:
33 | theme: [flatly, theme.scss]
34 | ```
35 |
36 | \
37 |
38 | [HTML theming Quarto docs](https://quarto.org/docs/output-formats/html-themes.html)
39 |
40 |
41 | ## SCSS files
42 |
43 | SCSS files have the following form:
44 |
45 | ``` scss
46 | /*-- scss:defaults --*/
47 | $h2-font-size: 1.6rem !default;
48 | $headings-font-weight: 500 !default;
49 | $body-color: $gray-700 !default;
50 |
51 | /*-- scss:rules --*/
52 | h1, h2, h3, h4, h5, h6 {
53 | text-shadow: -1px -1px 0 rgba(0, 0, 0, .3);
54 | }
55 | ```
56 |
57 | \
58 |
59 | Define [**SASS variables**](https://quarto.org/docs/output-formats/html-themes.html#sass-variables) in the `defaults` section.
60 |
61 | Declare [**CSS rules**](https://www.w3schools.com/css/css_syntax.ASP) in the `rules` section.
62 |
63 | \
64 |
65 | [Bootstrap docs](https://getbootstrap.com/docs/5.1/customize/sass/)
66 |
67 | [Default Bootstrap variables](https://github.com/twbs/bootstrap/blob/main/scss/_variables.scss)
68 |
69 | ## Browser developer tools
70 |
71 | ::: r-stack
72 | {.fragment
73 | fig-alt="Screenshot of browser developer tools inspecting the Quarto title meta heading of an HTML report."
74 | width="1300" fig-align="left"}
75 |
76 | {.fragment
77 | fig-alt="Screenshot of browser developer tools with the CSS declaration modified to test style changes."
78 | width="1300" fig-align="left"}
79 | :::
80 |
81 | # MS Word {.section}
82 |
83 | ## Reference document
84 |
85 | Create and modify a *reference document*, which is a special kind of template.
86 |
87 | . . .
88 |
89 | 1. Run the following in the Terminal to create the reference doc:
90 |
91 | ```{.bash filename="Terminal"}
92 | quarto pandoc -o word-template.docx --print-default-data-file reference.docx
93 | ```
94 |
95 | . . .
96 |
97 | 2. Open `word-template.docx` and modify the styles.
98 |
99 | . . .
100 |
101 | 3. Set this template in the YAML under the `reference-doc:` key:
102 |
103 | ```yaml
104 | format:
105 | docx:
106 | reference-doc: word-template.docx
107 | ```
108 |
109 | . . .
110 |
111 | [MS Word template Quarto docs](https://quarto.org/docs/output-formats/ms-word-templates.html)
112 |
113 | [MS documentation on modifying styles](https://support.microsoft.com/en-us/office/customize-or-create-new-styles-d38d6e47-f6fc-48eb-a607-1eb120dec563)
114 |
115 | ## Need your report as a PDF?
116 |
117 | Format in MS Word and then convert `.docx` to `.pdf` with Adobe Acrobat.
118 |
119 | or...
120 |
121 | - Learn how to format PDFs in the Quarto docs: [PDF basics](https://quarto.org/docs/output-formats/pdf-basics.html) & [PDF options](https://quarto.org/docs/reference/formats/pdf.html).
122 |
123 | - Try [Typst](https://quarto.org/docs/output-formats/typst.html), an open-source markup-based typesetting system, new in Quarto 1.4.
124 |
125 | # 💪🏼 Exercise {.exercise}
126 |
127 | **Play around with the HTML and MS Word styling of a report of your choosing.**
128 |
129 | 1. Open a new `.qmd` or choose one from a previous exercise.
130 | 2. Add a [Bootswatch](https://bootswatch.com/) theme to the YAML and re-render.
131 | 3. Create a MS Word reference doc, [modify a style](https://support.microsoft.com/en-us/office/customize-or-create-new-styles-d38d6e47-f6fc-48eb-a607-1eb120dec563), add it to the YAML, and re-render.
132 |
133 | ```{.bash}
134 | # Run in the Terminal
135 |
136 | quarto pandoc -o word-template.docx --print-default-data-file reference.docx
137 | ```
138 |
139 | ```{r}
140 | #| echo: false
141 | countdown::countdown(minutes = 7, top = 0)
142 | ```
143 |
--------------------------------------------------------------------------------
/5-style/images/browser-tools-modified.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/5-style/images/browser-tools-modified.png
--------------------------------------------------------------------------------
/5-style/images/browser-tools.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/5-style/images/browser-tools.png
--------------------------------------------------------------------------------
/5-style/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Styling reports"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](5-style.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/6-summary/6-summary.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "🏁 Summary {width=5em}"
3 | format: revealjs
4 | ---
5 |
6 | ## Learning objective 1
7 |
8 | **Understand what parameterized reporting is and when it is useful.**
9 |
10 | . . .
11 |
12 | **Like very fancy custom functions:**
13 |
14 | ::: incremental
15 |
16 | - Function → `.qmd` template
17 |
18 | - Input → parameters
19 |
20 | - Output → rendered reports
21 | :::
22 |
23 | . . .
24 |
25 | **Useful for creating variations of the same report:**
26 |
27 | - Spatial: country, state, county, or city
28 |
29 | - Temporal: year, month or other time period
30 |
31 | - Anything you can filter by: breeds, species, diseases, water bodies, customers, trials, etc.
32 |
33 | . . .
34 |
35 | ::: callout-note
36 | We only covered reports, but you can also parameterize `revealjs` presentations! See this [Jumping Rivers blog post](https://www.jumpingrivers.com/blog/r-parameterised-presentations-quarto/) about it.
37 | :::
38 |
39 | ## Learning objective 2a
40 |
41 | **Convert a Quarto document into a parameterized template.**
42 |
43 | ::: incremental
44 | - Include default `params:` in YAML
45 |
46 | - Replace hard-coded values with `params$pet_type`
47 |
48 | - **YAML**:
49 |
50 | ``` {yaml}
51 | ---
52 | title: "Report about `r params$pet_type`"
53 | params:
54 | pet_type: "cats"
55 | ---
56 | ```
57 |
58 | - **Inline R code**:
59 |
60 | ```{markdown}
61 | I like **`r params$pet_type`**.
62 | ```
63 |
64 | - **Code chunks**:
65 |
66 | ``` r
67 | pets |>
68 | dplyr::filter(pet_type == params$pet_type)
69 | ```
70 | :::
71 |
72 | ## Learning objective 2b
73 |
74 | **Render all variations of the report at once using [{quarto}](https://quarto-dev.github.io/quarto-r/) and [{purrr}](https://purrr.tidyverse.org/).**
75 |
76 | ::: {.fragment}
77 | 1. Get all unique parameter combinations into a dataframe:
78 |
79 | ```{r}
80 | #| echo: false
81 | pet_reports <- readRDS("../data/pet-reports.RDS")
82 | ```
83 |
84 |
85 | ```{r}
86 | head(pet_reports, 2)
87 | ```
88 |
89 | :::
90 |
91 | ::: {.fragment}
92 | 2. Use dataframe in `pwalk()` with `quarto_render()`:
93 |
94 | ```{r}
95 | #| eval: false
96 | purrr::pwalk(
97 | pet_reports,
98 | quarto::quarto_render,
99 | input = here::here("pet_template.qmd"),
100 | .progress = TRUE
101 | )
102 | ```
103 | :::
104 |
105 | ## Learning objective 3a
106 |
107 | **Generate multiple format outputs from the same .qmd using [conditional content]{style="font-size:larger;text-decoration: underline;"}.**
108 |
109 | Create a div, span, or non-executable code block with one option from each of the below columns:
110 |
111 | :::: {.columns}
112 |
113 | ::: {.column width="30%"}
114 | **Class**
115 |
116 | - `.content-visible`
117 | - `.content-hidden`
118 | :::
119 |
120 | ::: {.column width="30%"}
121 | **Attribute**
122 |
123 | - `when-format="___"`
124 | - `unless-format="___"`
125 | :::
126 |
127 | ::: {.column width="30%"}
128 | **Format**
129 |
130 | - `latex` or `pdf`
131 | - `epub`
132 | - `html` or `revealjs`
133 | - `markdown`
134 | :::
135 | ::::
136 |
137 | :::: {.fragment style="margin-top:-2em"}
138 |
139 | **Example to show tabset only for HTML reports:**
140 |
141 | ```markdown
142 | :::: {.content-visible when-format="html"}
143 | ::: panel-tabset
144 | {{{< include _4-report-content.qmd >}}}
145 | :::
146 | ::::
147 | ```
148 | ::::
149 |
150 | ## Learning objective 3b
151 |
152 | **Generate multiple format outputs from the same .qmd using [conditional code execution]{style="font-size:larger;text-decoration: underline;"}**.
153 |
154 | ::: panel-tabset
155 |
156 | ## Conditional on output
157 |
158 | 1. Get the Pandoc output format.
159 |
160 | ```r
161 | #| label: setup
162 |
163 | format <- knitr::opts_knit$get("rmarkdown.pandoc.to")
164 | ```
165 |
166 | 2. Use `format` in the `eval: !expr` chunk option.
167 |
168 | ```r
169 | #| label: interactive-plot
170 | #| eval: !expr format == "html"
171 |
172 | # plotly code
173 | ```
174 |
175 | ## Conditional on parameter
176 |
177 | Use `params` in the `eval: !expr` chunk option.
178 |
179 | ```r
180 | #| eval: !expr params$fave_breed == "Snowshoe"
181 |
182 | # Code for a special plot for my favorite cat breed.
183 | ```
184 | :::
185 |
186 | ## Learning objective 3c
187 |
188 | **Generate multiple format outputs from the same .qmd using [custom styling]{style="font-size:larger;text-decoration: underline;"}.**
189 |
190 | ::: panel-tabset
191 |
192 | ## HTML: Bootswatch & SCSS file
193 |
194 | 1. Pick a [Bootswatch](https://bootswatch.com/) theme.
195 |
196 | 2. Customize with a `.scss` file.
197 |
198 | 3. Use browser developer tools to find/test more styling.
199 |
200 | ``` yaml
201 | format:
202 | html:
203 | theme: [flatly, theme.scss]
204 | ```
205 |
206 | ## MS Word: reference doc
207 |
208 | 1. Create the reference doc.
209 |
210 | ```{.bash filename="Terminal"}
211 | quarto pandoc -o word-template.docx --print-default-data-file reference.docx
212 | ```
213 |
214 | 2. Open `word-template.docx` and modify the styles.
215 |
216 | 3. Set this template in the YAML under the `reference-doc:` key:
217 |
218 | ```yaml
219 | format:
220 | docx:
221 | reference-doc: word-template.docx
222 | ```
223 | :::
224 |
225 | ## Thank you!
226 |
227 | ::: columns
228 | ::: {.column width="65%"}
229 | 🏡 **Home for all workshop materials**:
230 | [jadeyryan.quarto.pub/cascadia-quarto/](https://jadeyryan.quarto.pub/cascadia-quarto/)
231 |
232 | \
233 |
234 | 🎥 **Recordings from previous workshops & talks**:
235 | [links in GitHub repo](https://github.com/jadeynryan/parameterized-quarto-workshop?tab=readme-ov-file#workshops) or [my YouTube playlist](https://youtube.com/playlist?list=PLzjGoNexcyYaDUVCg4MQDtMXLl2F5HE3B&si=-y0jQfCYyRAQjI1B)
236 |
237 | {width="600"
238 | fig-alt="From left to right, Mai, Tai, and Skye. Three snowshoe cats cuddling in their warming beds."
239 | style="border-radius:1em"}
240 | :::
241 |
242 | ::: {.column width="35%"}
243 | **Let's stay connected!**
244 |
245 | {{< fa link size=xl >}} [jadeyryan.com](https://jadeyryan.com)
246 |
247 | {{< fa brands mastodon size=xl >}} [\@jadeynryan](https://fosstodon.org/@jadeynryan)
248 |
249 | {{< fa brands linkedin size=xl >}} [linkedin.com/in/jadey-ryan](https://www.linkedin.com/in/jadey-ryan)
250 |
251 | {{< fa brands github size=xl >}} [jadeynryan](https://github.com/jadeynryan/)
252 |
253 | {{< fa brands etsy size=xl >}} [thecodingcats.etsy.com](https://thecodingcats.etsy.com/)
254 | :::
255 | :::
256 |
--------------------------------------------------------------------------------
/6-summary/images/mts.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/6-summary/images/mts.jpg
--------------------------------------------------------------------------------
/6-summary/index.qmd:
--------------------------------------------------------------------------------
1 | ---
2 | title: "Summary"
3 | format: html
4 | ---
5 |
6 | [View slides in full screen](6-summary.qmd).
7 |
8 | ```{=html}
9 |
10 | ```
11 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Reproducible and Parameterized Quarto Workshops
2 |
3 | ------------------------------------------------------------------------
4 |
5 | ## Workshops
6 |
7 | ### Upcoming
8 |
9 | ### Past
10 |
11 | #### Intermediate Quarto: Parameterized Reports
12 |
13 | [Cascadia R Conference](https://cascadiarconf.com/) 2024 Workshop
14 |
15 | 📆 June 21, 2024 // 1:30 pm - 4:30 pm PT\
16 | 🏫 University of Washington, South Lake Union, Building C\
17 | 🧾 [EventBrite
18 | registration](https://www.eventbrite.com/e/cascadia-r-conf-2024-tickets-851137203287)\
19 | 🏡 [Workshop website](https://jadeyryan.quarto.pub/cascadia-quarto)\
20 | 🐙 [GitHub release](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/cascadia)
21 |
22 | The [Intro to Quarto workshop](https://charlotte.quarto.pub/cascadia/)
23 | takes you through the basics of authoring a reproducible report using
24 | Quarto. This workshop builds on those concepts and teaches you how to
25 | level up your reproducible reports by using parameters, conditional
26 | content, conditional code execution, and custom styling sheets for HTML
27 | and Microsoft Word formats. Additionally, you will learn how to render
28 | all variations of a parameterized report at once using `quarto` and
29 | `purrr`.
30 |
31 | #### Reproducible Reporting with Quarto
32 |
33 | Hosted by the [Community Engaged Data
34 | Science](https://coa-community-data-science.netlify.app/) undergraduate
35 | course taught by [Dr. Laurie Baker](https://lauriebaker.rbind.io/).
36 |
37 | 📆 April 25, 2024 // 1:00 pm - 4:00 pm ET\
38 | 🏫 Hybrid // College of the Atlantic\
39 | 🆓 **FREE** with
40 | [registration](https://www.meetup.com/maine-r-users-group/events/300459430/)\
41 | 🏡 [Workshop
42 | website](https://jadeyryan.quarto.pub/ceds-quarto-workshop)\
43 | 🐙 [GitHub
44 | release](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/coa-ceds)
45 |
46 | Join this interactive workshop to learn what Quarto is and its impact on
47 | data communication and sharing. In this session, we will 1) explore how
48 | Quarto seamlessly integrates code and text to create reproducible
49 | reports and presentations; 2) dive into real-world applications at the
50 | Washington State Department of Agriculture; and 3) learn and practice
51 | Quarto functionality through demonstrations and hands-on exercises
52 | covering static and dynamic output formats, markdown syntax, code chunk
53 | options, output theming, and parameters for document variations.
54 |
55 | #### Parameterized Reporting with Quarto
56 |
57 | Hosted by R-Ladies Abuja
58 |
59 | 📆 February 21, 2024 // 4:30 pm - 6:30 pm WAT\
60 | 🏨 Virtual\
61 | 🆓 **FREE** with
62 | [registration](https://www.meetup.com/rladies-abuja/events/298688371/)\
63 | 🏡 [Workshop
64 | website](https://jadeyryan.quarto.pub/rladies-abuja-quarto-params)\
65 | 🐙 [GitHub
66 | release](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/rladies-abuja)\
67 | 🎥 [Recording](https://youtu.be/kQn82pa04jQ?si=Ksvdp0Hdgs1crOD0)
68 |
69 | Tired of manually adjusting Quarto reports for different regions, time
70 | periods, or clients? Dreaming of using just one template to generate
71 | both interactive HTML and static Word/PDF versions of your reports?
72 |
73 | Join our workshop to unlock the power of parameterized reporting with
74 | Quarto and leave with your own template and examples to modify for your
75 | own projects.
76 |
77 | #### Parameterized Reporting with Quarto
78 |
79 | Hosted by R-Ladies Washington DC
80 |
81 | 📆 January 18, 2024 // 6:30 pm - 8:30 pm ET\
82 | 🏨 Virtual\
83 | 🆓 **FREE** with
84 | [registration](https://www.meetup.com/rladies-dc/events/297344107/)\
85 | 🏡 [Workshop
86 | website](https://jadeyryan.quarto.pub/rladies-dc-quarto-params/)\
87 | 🐙 [GitHub
88 | release](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/rladies-dc)\
89 | 🎥 [Recording](https://youtu.be/MKjz_xkMgxY)
90 |
91 | Tired of manually adjusting Quarto reports for different regions, time
92 | periods, or clients? Dreaming of using just one template to generate
93 | both interactive HTML and static Word/PDF versions of your reports?
94 |
95 | Join our workshop to unlock the power of parameterized reporting with
96 | Quarto and leave with your own template and examples to modify for your
97 | own projects.
98 |
99 | ## Speaker
100 |
101 | **Jadey Ryan**
102 |
103 | Jadey is a data scientist at the [Natural Resources and Agricultural
104 | Sciences section](https://agr.wa.gov/AgScience) of the WA Dept. of
105 | Agriculture. She is an R enthusiast obsessed with efficiently creating
106 | beautiful data products and decision-support tools, especially with
107 | Quarto. Away from the computer, catch her trying new foods with her
108 | husband, snuggling with her three cats, or taking leisurely strolls in
109 | the great outdoors.
110 |
111 | Learn more at [jadeyryan.com](https://jadeyryan.com).
112 |
113 | ## Acknowledgements
114 |
115 | This workshop structure has been adapted from:
116 |
117 | - [R/Medicine Data Cleaning 2023
118 | Workshop](https://shannonpileggi.github.io/rmedicine-data-cleaning-2023/)
119 | taught by [Crystal Lewis](https://cghlewis.com/), [Shannon
120 | Pileggi](https://www.pipinghotdata.com/), and [Peter
121 | Higgins](https://bookdown.org/pdr_higgins/rmrwr/)
122 |
123 | - [ASA Traveling Courses on
124 | Quarto](https://quarto.org/docs/blog/posts/2023-12-05-asa-traveling-courses/)
125 | taught by [Mine Çetinkaya-Rundel](https://mine-cr.com/) and [Andrew
126 | Bray](https://andrewpbray.github.io/)
127 |
128 | ------------------------------------------------------------------------
129 |
130 | 
131 |
132 | This work is released under the [Creative Commons
133 | Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA)
134 | license](https://creativecommons.org/licenses/by-nc-sa/4.0/).
135 |
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/_extension.yml:
--------------------------------------------------------------------------------
1 | title: Font Awesome support
2 | author: Carlos Scheidegger
3 | version: 1.1.0
4 | quarto-required: ">=1.2.269"
5 | contributes:
6 | shortcodes:
7 | - fontawesome.lua
8 |
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/css/latex-fontsize.css:
--------------------------------------------------------------------------------
1 | .fa-tiny {
2 | font-size: 0.5em;
3 | }
4 | .fa-scriptsize {
5 | font-size: 0.7em;
6 | }
7 | .fa-footnotesize {
8 | font-size: 0.8em;
9 | }
10 | .fa-small {
11 | font-size: 0.9em;
12 | }
13 | .fa-normalsize {
14 | font-size: 1em;
15 | }
16 | .fa-large {
17 | font-size: 1.2em;
18 | }
19 | .fa-Large {
20 | font-size: 1.5em;
21 | }
22 | .fa-LARGE {
23 | font-size: 1.75em;
24 | }
25 | .fa-huge {
26 | font-size: 2em;
27 | }
28 | .fa-Huge {
29 | font-size: 2.5em;
30 | }
31 |
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Brands-Regular-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Brands-Regular-400.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Brands-Regular-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Brands-Regular-400.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Regular-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Regular-400.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Regular-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Regular-400.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Solid-900.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Solid-900.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Solid-900.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/FontAwesome6Free-Solid-900.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-brands-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-brands-400.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-brands-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-brands-400.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-regular-400.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-regular-400.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-regular-400.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-regular-400.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-solid-900.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-solid-900.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-solid-900.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-solid-900.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-v4compatibility.ttf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-v4compatibility.ttf
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-v4compatibility.woff2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/jadeynryan/parameterized-quarto-workshop/b7ca2fc86f2a1d0c1c7328395657577a0ab47cd3/_extensions/quarto-ext/fontawesome/assets/webfonts/fa-v4compatibility.woff2
--------------------------------------------------------------------------------
/_extensions/quarto-ext/fontawesome/fontawesome.lua:
--------------------------------------------------------------------------------
1 | local function ensureLatexDeps()
2 | quarto.doc.use_latex_package("fontawesome5")
3 | end
4 |
5 | local function ensureHtmlDeps()
6 | quarto.doc.add_html_dependency({
7 | name = 'fontawesome6',
8 | version = '0.1.0',
9 | stylesheets = {'assets/css/all.css', 'assets/css/latex-fontsize.css'}
10 | })
11 | end
12 |
13 | local function isEmpty(s)
14 | return s == nil or s == ''
15 | end
16 |
17 | local function isValidSize(size)
18 | local validSizes = {
19 | "tiny",
20 | "scriptsize",
21 | "footnotesize",
22 | "small",
23 | "normalsize",
24 | "large",
25 | "Large",
26 | "LARGE",
27 | "huge",
28 | "Huge"
29 | }
30 | for _, v in ipairs(validSizes) do
31 | if v == size then
32 | return size
33 | end
34 | end
35 | return ""
36 | end
37 |
38 | return {
39 | ["fa"] = function(args, kwargs)
40 |
41 | local group = "solid"
42 | local icon = pandoc.utils.stringify(args[1])
43 | if #args > 1 then
44 | group = icon
45 | icon = pandoc.utils.stringify(args[2])
46 | end
47 |
48 | local title = pandoc.utils.stringify(kwargs["title"])
49 | if not isEmpty(title) then
50 | title = " title=\"" .. title .. "\""
51 | end
52 |
53 | local label = pandoc.utils.stringify(kwargs["label"])
54 | if isEmpty(label) then
55 | label = " aria-label=\"" .. icon .. "\""
56 | else
57 | label = " aria-label=\"" .. label .. "\""
58 | end
59 |
60 | local size = pandoc.utils.stringify(kwargs["size"])
61 |
62 | -- detect html (excluding epub which won't handle fa)
63 | if quarto.doc.is_format("html:js") then
64 | ensureHtmlDeps()
65 | if not isEmpty(size) then
66 | size = " fa-" .. size
67 | end
68 | return pandoc.RawInline(
69 | 'html',
70 | ""
71 | )
72 | -- detect pdf / beamer / latex / etc
73 | elseif quarto.doc.is_format("pdf") then
74 | ensureLatexDeps()
75 | if isEmpty(isValidSize(size)) then
76 | return pandoc.RawInline('tex', "\\faIcon{" .. icon .. "}")
77 | else
78 | return pandoc.RawInline('tex', "{\\" .. size .. "\\faIcon{" .. icon .. "}}")
79 | end
80 | else
81 | return pandoc.Null()
82 | end
83 | end
84 | }
85 |
--------------------------------------------------------------------------------
/_freeze/1-welcome/1-welcome/execute-results/html.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "75fa531d560a37bdae729ab7d050df0c",
3 | "result": {
4 | "engine": "knitr",
5 | "markdown": "---\ntitle: \"Welcome! {width=5em}\"\nformat: revealjs\n---\n\n\n\n## While waiting for us to begin...\n\nOpen the workshop website and make sure you've completed the pre-work\nand have the required software, packages, and exercises.\n\n[**jadeyryan.quarto.pub/cascadia-quarto/prework**](https://jadeyryan.quarto.pub/cascadia-quarto/prework).\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nusethis::use_course(\n \"https://github.com/jadeynryan/parameterized-quarto-workshop/raw/cascadia/exercises/intermediate-exercises.zip\"\n# , destdir = \"C:/Users/jryan/Documents/R/projects\"\n )\n\ninstall.packages(c(\"dplyr\", \"fs\", \"ggplot2\", \"here\", \"janitor\", \"knitr\", \"lubridate\",\n \"plotly\", \"purrr\", \"quarto\", \"readr\", \"rmarkdown\", \"stringr\", \"tidyr\"))\n```\n:::\n\n\n\nIf `use_course()` didn't work, manually download the zip file from\nGitHub:\n[github.com/jadeynryan/parameterized-quarto-workshop/tree/cascadia/exercises](https://github.com/jadeynryan/parameterized-quarto-workshop/tree/cascadia/exercises).\n\n::: callout-tip\n## Backup option: Posit Cloud\n\nJoin the Posit Cloud [Quarto Cascadia\nworkspace](https://posit.cloud/spaces/519059/join?access_code=ckv18LHEcSw3QtQ904uvpzLVlh4L2rk6RhKdpwyp)\nand open the [Intermediate Exercises\nproject](https://posit.cloud/spaces/519059/content/8351107).\n:::\n\n## Acknowledgements\n\n{.center fig-alt=\"Cascadia R Conf logo\"\nheight=\"350px\"}\n\n\\\n\n**Workshop structure adapted from:**\n\n[R/Medicine Data Cleaning 2023\nWorkshop](https://shannonpileggi.github.io/rmedicine-data-cleaning-2023/)\ntaught by [Crystal Lewis](https://cghlewis.com/), [Shannon\nPileggi](https://www.pipinghotdata.com/), and [Peter\nHiggins](https://bookdown.org/pdr_higgins/rmrwr/)\n\n\\\n\n[ASA Traveling Courses on\nQuarto](https://quarto.org/docs/blog/posts/2023-12-05-asa-traveling-courses/)\ntaught by [Mine Çetinkaya-Rundel](https://mine-cr.com/) and [Andrew\nBray](https://andrewpbray.github.io/)\n\n## Code of Conduct\n\nPlease review and abide by:\n[cascadiarconf.com/policies/](https://cascadiarconf.com/policies/)\n\n\\\n\n💙 Treat everyone with respect and kindness.\n\n\\\n\n💜 Everyone should feel welcome and safe.\n\n## Disclaimer and license\n\nOpinions expressed are solely my own and do not express the views of my\nemployer or any organizations I am associated with.\n\n\\\n\nThis work is licensed under [Creative Commons\nAttribution-NonCommercial-ShareAlike 4.0 International (CC\nBY-NC-SA)](https://creativecommons.org/licenses/by-nc-sa/4.0/).\n\n\n\n{{< fa brands creative-commons size=2x >}} {{< fa brands creative-commons-by size=2x >}} {{< fa brands creative-commons-nc size=2x >}} {{< fa brands creative-commons-sa size=2x >}}\n\n\n\n\n\n## Meet Jadey Ryan\n\n::: columns\n::: {.column width=\"44%\"}\nData scientist at WA Dept of Agriculture\n\nThe Coding Cats: cat & code themed merch\n\n{{< fa link size=xl >}} [jadeyryan.com](https://jadeyryan.com)\n\n{{< fa brands mastodon size=xl >}} [\\@jadeynryan](https://fosstodon.org/@jadeynryan)\n\n{{< fa brands linkedin size=xl >}} [linkedin.com/in/jadey-ryan](https://www.linkedin.com/in/jadey-ryan)\n\n{{< fa brands github size=xl >}} [jadeynryan](https://github.com/jadeynryan/)\n\n{{< fa brands etsy size=xl >}} [thecodingcats.etsy.com](https://thecodingcats.etsy.com/)\n\n{fig-alt=\"Three snowshoe siamese cats in loaf mode. From left to right: Tai, Mai, and Skye\" style=\"border-radius:1em;margin-top:auto\"}\n:::\n\n::: {.column width=\"28%\"}\n{fig-alt=\"Jadey collecting a bulk density soil sample in a field of wheat stubble.\" style=\"border-radius:1em;margin-top:auto\"}\n:::\n\n::: {.column width=\"28%\"}\n::: {layout-nrow=\"2\"}\n{style=\"border-radius:1em;margin-top:auto\"\nfig-alt=\"Jadey standing in a field of wheat stubble holding a 3 foot long soil sampling probe over her shoulder.\"}\n\n{fig-alt=\"Jadey standing in a grazed wildflower meadow with two colleagues collecting soil samples.\"\nstyle=\"border-radius:1em;margin-top:auto\"}\n:::\n\n{{< fa camera title=\"Photo credit\" >}} [@leslie.mmichel](https://twitter.com/leslie_mmichel)\n:::\n:::\n\n## Meet our TA: Lydia Gibson\n\n{.center fig-alt=\"Photo of Lydia Gibson\" style=\"border-radius:1em;\"}\n\n## Learning objectives\n\n::: incremental\n- Understand what parameterized reporting is and when it is useful.\n- Convert a Quarto document into a parameterized template and render\n all variations.\n- Generate multiple format outputs from the same template using:\n - conditional content\n - conditional code execution, and\n - custom styling.\n:::\n\n## Schedule\n\n| Time | Topic |\n|-------------|------------------------------------------------------|\n| 1:30 - 2:00 | Welcome & [Parameterizing reports](../2-parameters/) |\n| 2:00 - 3:00 | [Rendering reports](../3-render/) |\n| 3:00 - 3:30 | Break |\n| 3:30 - 4:00 | [Conditional content & code](../4-conditionals/) |\n| 4:00 - 4:20 | [Styling reports](../5-styling/) |\n| 4:20 - 4:30 | [Summary](../6-summary/) |\n\n## Workshop structure\n\nPresentation\n\n💃🏻 Demos\n\n💪🏻 Exercises\n\n\\\n\n. . .\n\nLet us know how you're doing by displaying your stickies!\n\n🟦 I'm all good; I'm done.\n\n🟧 I'm a little lost; I could use some help.\n\n# 💪🏼 Exercise {.exercise}\n\n**Meet your neighbors**:\n\n- Your name\n\n- Your favorite snack 🍎🧀🍦🍫🍿\n\n- What kinds of reports are you wanting to create after today's\n workshop?\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n
\n\n05:00\n
\n```\n\n:::\n:::\n",
6 | "supporting": [],
7 | "filters": [
8 | "rmarkdown/pagebreak.lua"
9 | ],
10 | "includes": {
11 | "include-in-header": [
12 | "\n\n"
13 | ],
14 | "include-after-body": [
15 | "\n\n\n"
16 | ]
17 | },
18 | "engineDependencies": {},
19 | "preserve": {},
20 | "postProcess": true
21 | }
22 | }
--------------------------------------------------------------------------------
/_freeze/2-parameters/2-parameters/execute-results/html.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "f4219177a054ba8a3b0b3a1b1b615355",
3 | "result": {
4 | "engine": "knitr",
5 | "markdown": "---\ntitle: \"Parameterizing reports {width=5em}\"\nformat: revealjs\n---\n\n\n\n## Examples of parameterized reports\n\n::: columns\n::: {.column width=\"25%\"}\n{.lightbox group=\"examples\"\nfig-alt=\"RStudio R Markdown parameterized report project for mapping ocean floors.\"}\n\n[Ocean floor maps](https://rmarkdown.rstudio.com/lesson-6.html)\n:::\n\n::: {.column width=\"25%\"}\n{.lightbox group=\"examples\"\nfig-alt=\"Report for Alabama spending with text and plots generated from parameterized R Markdown.\"}\n\n[Fiscal\nbriefs](https://book.rwithoutstatistics.com/parameterized-reports-chapter.html)\n:::\n\n::: {.column width=\"25%\"}\n{.lightbox group=\"examples\"\nfig-alt=\"Report for Alaska driver quality with text, plot, and table generated from parameterized RMarkdown.\"}\n\n[Bad\ndrivers](https://urban-institute.medium.com/iterated-fact-sheets-with-r-markdown-d685eb4eafce)\n:::\n\n::: {.column width=\"25%\"}\n{.lightbox group=\"examples\"\nfig-alt=\"HTML report for soil health survey participant, generated from a parameterized Quarto report.\"}\n\n[Soil health](https://wa-department-of-agriculture.github.io/soils/)\n:::\n:::\n\n. . .\n\n\\\n\n**Another use case: different audiences, different reports**\n\nShow code for technical staff and hide code for everyone else ([StackOverflow\nexample](https://stackoverflow.com/questions/73571919/how-to-pass-logical-parameters-with-the-quarto-r-package-to-the-knitr-chunk-opti)).\n\n## Like a custom function\n\n::: r-stack\n{.fragment\nfig-alt=\"File with the word '.qmd' inside and the word 'Function' above.\"\nwidth=\"1300\" fig-align=\"left\" style=\"margin-top:-1em\"}\n\n{.fragment\nfig-alt=\"An arrow points from 'Input' with 'params$year' to the previous image with 'Function' and '.qmd' file.\"\nwidth=\"1300\" fig-align=\"left\" style=\"margin-top:-1em\"}\n\n{.fragment\nfig-alt=\"In addition to the previous two images, arrows point to five reports with years 2019 through 2023 on them in a flow chart.\"\nwidth=\"1300\" fig-align=\"left\" style=\"margin-top:-1em\"}\n:::\n\n## What makes a report \"parameterized\"?\n\n- YAML header with `params` key-value pairs\n\n- Use these `params` to create different variations of a report from a single `.qmd` document.\n\n. . .\n\n::: callout-important\n- Valid parameter values are strings, numbers, or Boolean.\n\n- Must serialize a dataframe to pass it as a parameter, then un-serialize it\n back to a dataframe within the `.qmd` content.\n\n- See [Christophe Dervieux's answer in Posit\n Community](https://community.rstudio.com/t/param-converted-from-data-frame-to-list/155556/9)\n to understand why.\n\n- See [John Paul Helveston's blog\n post](https://www.jhelvy.com/posts/2023-02-28-parameterized-pdfs-with-quarto/#passing-data-frames-as-parameters)\n to learn how to use {jsonlite} as a workaround.\n:::\n\n## Workflow\n\n::: incremental\n1. Write report template with default values hard-coded, and then render & review.\n\n2. Set default `params` key-value pairs in YAML. \n\n3. Replace hard-coded values with the `params` variables.\n\n4. Render the single report and review.\n\n5. Render extreme cases and review.\n\n - Parameter values with barely any data and with tons of data.\n\n6. Render all variations of the report at once.\n:::\n\n# 💪🏼 Exercise {.exercise}\n\n**Explore a report without parameters and see where we could add them.**\n\n1. Open `1-swiss-cats.qmd`.\n\n2. Click the\n {fig-alt=\"Quarto render button in RStudio\" style=\"vertical-align:middle;\" width=\"49\"} **Render** button.\n\n3. Look at the source markdown & code and the rendered report.\n\n4. 💬 **Chat**: What variables could we set as parameters?\n\n 💡 **Hint**: run the `setup` chunk and look at the `pets` dataframe to see\n what variables it has.\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n
\n\n05:00\n
\n```\n\n:::\n:::\n\n\n\n## Set `params` in YAML header\n\n```{.yaml code-line-numbers=\"|2|3,4,6|5|7-8|11\"}\n---\ntitle: \"Swiss Cats\" # Metadata\nformat: # Set format types\n html:\n toc: true # Set additional options\n docx: default \nparams: # Set default parameter key-value pairs\n fave_breed: \"Snowshoe\" \n---\n \nReport content goes here. # Write narrative and code\n```\n\n. . .\n\n::: callout-important\nYour default `params` key-value pairs must be found in your dataset. Otherwise, code will error or output will be blank.\n\nThe variable name for `params` can be anything you choose. Often, it's a column name in your dataset.\n:::\n\n## Access `params`\n\n\n\n\n\n\n\nRun any line or chunk to add `params` to your environment.\n\n. . .\n\n`params` object is a list.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nstr(params)\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\nList of 1\n $ fave_breed: chr \"Snowshoe\"\n```\n\n\n:::\n:::\n\n\n\n\\\n\n. . .\n\nAccess with `$` notation.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\nparams$fave_breed\n```\n\n::: {.cell-output .cell-output-stdout}\n\n```\n[1] \"Snowshoe\"\n```\n\n\n:::\n:::\n\n\n\n\\\n\n. . .\n\nFor inline code in YAML or report content, enclose the expression in `` `r ` ``.\n\n```markdown\nMy favorite cat breed is the **`r params$fave_breed`**.\n```\n\nMy favorite cat breed is the **Snowshoe**.\n\n## Replace hard-coded values with `params`\n\n`Cmd`/`Ctrl` + `F` to find where to replace hard-coded values with `params`.\n\n{fig-alt=\"Find and replace toolbar with "pet_type in the Search field highlighted by a purple box and "params$pet_type in the Replace field highlighted by a blue box. The .qmd file shows a filter statement with the "pet_type highlighted by RStudio as a match for the Find tool. This filter statement is highlighted by a purple box with an arrow pointing to a blue box that has the filter statement with the hard-coded "cats string replaced with "params$pet_type.\"}\n\n## Replace hard-coded values with `params`\n\n**Use `$` list notation in code** for plot/table titles and labels, filtering, etc.\n\n\\\n\n`paste()` syntax:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# ggplot2 code +\n labs(title = paste(params$fave_breed, \"population\"))\n```\n:::\n\n\n\n. . .\n\n\\\n\n`glue::glue()` syntax:\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# ggplot2 code +\n labs(title = glue::glue(\"{params$fave_breed} population\"))\n```\n:::\n\n\n\n\\\n\n. . .\n\n**Use inline R code** for markdown.\n\n```markdown\n## My favorite breed: **`r params$fave_breed`**.\n```\n\n##\n\n{fig-align=\"center\"}\n\n# 💃🏻 Demo {.demo}\n\nModify `1-swiss-cats-demo.qmd` to add `pet_type` and `fave_breed` parameters.\n\n\\\n\nThis parameterized version of `1-swiss-cats.qmd` is the starting point for the next section's exercises (`2-quarto-render.qmd`).\n",
6 | "supporting": [],
7 | "filters": [
8 | "rmarkdown/pagebreak.lua"
9 | ],
10 | "includes": {
11 | "include-in-header": [
12 | "\n\n"
13 | ],
14 | "include-after-body": [
15 | "\n\n\n"
16 | ]
17 | },
18 | "engineDependencies": {},
19 | "preserve": {},
20 | "postProcess": true
21 | }
22 | }
--------------------------------------------------------------------------------
/_freeze/4-conditionals/4-conditionals/execute-results/html.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "b01822cd1d328b14ab03f3a3a6971f90",
3 | "result": {
4 | "engine": "knitr",
5 | "markdown": "---\ntitle: \"Conditional content & code {width=4em}\"\nformat: revealjs\n---\n\n\n\n# Conditional content {.section}\n\n## Control content visibility\n\nCreate a div, span, or non-executable code block with one option from each of the below columns:\n\n`{.class attribute=\"format\"}`\n\n:::: {.columns}\n\n::: {.column width=\"30%\"}\n**Class**\n\n- `.content-visible`\n- `.content-hidden`\n:::\n\n::: {.column width=\"30%\"}\n**Attribute**\n\n- `when-format=\"___\"`\n- `unless-format=\"___\"`\n:::\n\n::: {.column width=\"30%\"}\n**Format**\n\n- `latex` or `pdf`\n- `epub`\n- `html` or `revealjs`\n- `markdown`\n:::\n\n::::\n\n:::: {.fragment style=\"margin-top:-3.5em\"}\n\n**Examples:**\n\n::: panel-tabset\n\n## Divs\n\n```markdown\n::: {.content-visible when-format=\"html\"}\n\nWill only appear in HTML.\n\n:::\n```\n\n## Spans\n\n``` markdown\nSome text\n[in HTML.]{.content-visible when-format=\"html\"}\n[in PDF.]{.content-visible when-format=\"pdf\"}\n```\n\n## Non-executable code\n\nFenced code blocks purely for documentation.\n\n````markdown\n```{.python .content-visible when-format=\"html\"}\n# code shown only in HTML\n2 + 2\n```\n````\n:::\n::::\n\n. . .\n\n[Conditional Quarto docs](https://quarto.org/docs/authoring/conditional.html) & [Format aliases](https://quarto.org/docs/authoring/conditional.html#format-matching)\n\n## Useful for static/interactive features\n\nPairs well with the `{{< include >}}` shortcode to re-use content without copying/pasting.\n\n. . .\n\n::::: panel-tabset\n\n## Static\n\n```markdown\n:::: {.content-visible unless-format=\"html\"}\n\n## Cats\n\n{{{< include _cats.qmd >}}}\n\n## Dogs\n\n{{{< include _dogs.qmd >}}}\n\n::::\n```\n\n## Interactive\n\n```markdown\n:::: {.content-visible when-format=\"html\"}\n::: panel-tabset\n\n## Cats\n\n{{{< include _cats.qmd >}}}\n\n## Dogs\n\n{{{< include _dogs.qmd >}}}\n\n:::\n::::\n```\n:::::\n\n. . .\n\n::: callout-tip\n## Good practice\nUse an underscore prefix for included files so they are automatically ignored by a Quarto render of a project ([Include shortcode Quarto docs](https://quarto.org/docs/authoring/includes.html)).\n:::\n\n# 💪🏼 Exercise {.exercise}\n\n**Use conditional content divs to control when tabsets are shown.**\n\n1. Modify `3-conditional-content.qmd` so that the `panel-tabset` is visible for HTML reports and hidden for all other formats.\n\n\\\n\n2. Try another way to get the same result.\n\n `{.content-visible when-format=\"html\"}` is essentially the same as `{.content-hidden unless-format=\"html\"}`.\n\n\\\n\n3. 💬 **Chat**: Besides tabsets, what other kinds of content might you want to make visible for only a certain format?\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n
\n\n05:00\n
\n```\n\n:::\n:::\n\n\n\n# Conditional code execution {.section}\n\n## Conditionally execute a code chunk\n\n::: incremental\n\n- More efficient to not execute code that generates interactive outputs for static reports.\n\n- Useful for executing interactive plot code (e.g., `plotly` or `ggiraph`) for HTML reports and static `ggplot2` code for all other formats. \n\n- Useful for executing different code based on a parameter value.\n\n- Not currently a feature of Quarto v1.4. Follow along with this [GitHub discussion](https://github.com/quarto-dev/quarto-cli/discussions/3260#discussioncomment-4573926).\n\n- Chunk options can use R code for option values with `!expr`. Learn about the limitations to this YAML \"tag\" literal syntax in the [Quarto Chunk Options reference](https://quarto.org/docs/computations/r.html#chunk-options).\n\n:::\n\n## Conditional code based on output\n\nGet the format of the Pandoc output by including the following in the setup chunk of your `.qmd` file:\n\n\n\n::: {.cell}\n\n````{.cell-code}\n```{{r}}\n#| label: setup\n\n# Get output format\nformat <- knitr::opts_knit$get(\"rmarkdown.pandoc.to\")\n```\n````\n:::\n\n\n\n## Use `eval: !expr` chunk option\n\n::: panel-tabset\n\n## Static plot\n\n```markdown\n#| echo: fenced\n#| eval: !expr format %in% c(\"latex\", \"docx\")\n\n# code to create static {ggplot2}\n```\n\n:::: callout-important\n## Use `latex` not `pdf`\n\n`format` comes from `knitr::opts_knit$get(\"rmarkdown.pandoc.to\")`. Pandoc uses LaTeX to create PDFs.\n\nQuarto [format aliases](https://quarto.org/docs/authoring/conditional.html#format-matching) won't work here.\n::::\n\n## Interactive plot\n\n```markdown\n#| echo: fenced\n#| eval: !expr format == \"html\"\n\n# code to create interactive {plotly}\n```\n\n:::\n\n# 💪🏼 Exercise {.exercise}\n\n**Conditionally execute `ggplot2` code for static reports & `plotly` code for interactive reports.**\n\n1. Open `5-conditional-code.qmd`.\n\n2. In the `ggplot2` code chunks and `plotly` code chunks, fill in the blanks for the `eval: ` option.\n\n\n\n::: {.cell}\n\n```{.r .cell-code}\n# Replace ___ with html, latex, or docx.\n\n#| eval: !expr format == \"___\"\n\n#| eval: !expr format %in% c(\"___\", \"___\")\n```\n:::\n\n\n\n3. 💬 **Chat**: How would you change the `eval: ` option to execute a chunk based on a parameter value rather than the output format?\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n
\n\n05:00\n
\n```\n\n:::\n:::\n\n\n\n## Conditional code based on parameter\n\nUse `params` in `!expr`:\n\n``` r\n#| eval: !expr params$fave_breed == \"Snowshoe\"\n\n# Code for a special plot for my favorite cat breed.\n```\n\n\\\n\n. . .\n\n``` r\n#| eval: !expr !params$fave_breed == \"Snowshoe\"\n\n# Code for a different plot for all other breeds.\n# Note the ! in front of params.\n```\n",
6 | "supporting": [],
7 | "filters": [
8 | "rmarkdown/pagebreak.lua"
9 | ],
10 | "includes": {
11 | "include-in-header": [
12 | "\n\n"
13 | ],
14 | "include-after-body": [
15 | "\n\n\n"
16 | ]
17 | },
18 | "engineDependencies": {},
19 | "preserve": {},
20 | "postProcess": true
21 | }
22 | }
--------------------------------------------------------------------------------
/_freeze/5-style/5-style/execute-results/html.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "fc09e6ce8648753e60b40ae3abcce0bc",
3 | "result": {
4 | "engine": "knitr",
5 | "markdown": "---\ntitle: \"Styling your reports {width=5em}\"\nformat: revealjs\n---\n\n\n\n# HTML {.section}\n\n## Bootswatch themes\n\nChoose from or customize one of 25 [Bootswatch](https://bootswatch.com/) themes.\n\n\\\n\n. . .\n\n**Set the theme** in the YAML under the `html` key:\n\n``` yaml\nformat:\n html:\n theme: flatly\n```\n\n\\\n\n. . .\n\n**Customize a theme** by including a custom `.scss` file under the `theme` key:\n\n``` yaml\nformat:\n html:\n theme: [flatly, theme.scss]\n```\n\n\\\n\n[HTML theming Quarto docs](https://quarto.org/docs/output-formats/html-themes.html)\n\n\n## SCSS files\n\nSCSS files have the following form:\n\n``` scss\n/*-- scss:defaults --*/\n$h2-font-size: 1.6rem !default;\n$headings-font-weight: 500 !default;\n$body-color: $gray-700 !default;\n\n/*-- scss:rules --*/\nh1, h2, h3, h4, h5, h6 {\n text-shadow: -1px -1px 0 rgba(0, 0, 0, .3);\n}\n```\n\n\\\n\nDefine [**SASS variables**](https://quarto.org/docs/output-formats/html-themes.html#sass-variables) in the `defaults` section.\n\nDeclare [**CSS rules**](https://www.w3schools.com/css/css_syntax.ASP) in the `rules` section.\n\n\\\n\n[Bootstrap docs](https://getbootstrap.com/docs/5.1/customize/sass/)\n\n[Default Bootstrap variables](https://github.com/twbs/bootstrap/blob/main/scss/_variables.scss)\n\n## Browser developer tools\n\n::: r-stack\n{.fragment\nfig-alt=\"Screenshot of browser developer tools inspecting the Quarto title meta heading of an HTML report.\"\nwidth=\"1300\" fig-align=\"left\"}\n\n{.fragment\nfig-alt=\"Screenshot of browser developer tools with the CSS declaration modified to test style changes.\"\nwidth=\"1300\" fig-align=\"left\"}\n:::\n\n# MS Word {.section}\n\n## Reference document\n\nCreate and modify a *reference document*, which is a special kind of template.\n\n. . .\n\n1. Run the following in the Terminal to create the reference doc:\n\n```{.bash filename=\"Terminal\"}\nquarto pandoc -o word-template.docx --print-default-data-file reference.docx\n```\n\n. . .\n\n2. Open `word-template.docx` and modify the styles.\n\n. . .\n\n3. Set this template in the YAML under the `reference-doc:` key:\n\n```yaml\nformat:\n docx:\n reference-doc: word-template.docx\n```\n\n. . .\n\n[MS Word template Quarto docs](https://quarto.org/docs/output-formats/ms-word-templates.html)\n\n[MS documentation on modifying styles](https://support.microsoft.com/en-us/office/customize-or-create-new-styles-d38d6e47-f6fc-48eb-a607-1eb120dec563)\n\n## Need your report as a PDF?\n\nFormat in MS Word and then convert `.docx` to `.pdf` with Adobe Acrobat.\n\nor...\n\n- Learn how to format PDFs in the Quarto docs: [PDF basics](https://quarto.org/docs/output-formats/pdf-basics.html) & [PDF options](https://quarto.org/docs/reference/formats/pdf.html).\n\n- Try [Typst](https://quarto.org/docs/output-formats/typst.html), an open-source markup-based typesetting system, new in Quarto 1.4.\n\n# 💪🏼 Exercise {.exercise}\n\n**Play around with the HTML and MS Word styling of a report of your choosing.**\n\n1. Open a new `.qmd` or choose one from a previous exercise.\n2. Add a [Bootswatch](https://bootswatch.com/) theme to the YAML and re-render.\n3. Create a MS Word reference doc, [modify a style](https://support.microsoft.com/en-us/office/customize-or-create-new-styles-d38d6e47-f6fc-48eb-a607-1eb120dec563), add it to the YAML, and re-render.\n\n```{.bash}\n# Run in the Terminal\n\nquarto pandoc -o word-template.docx --print-default-data-file reference.docx\n```\n\n\n\n::: {.cell}\n::: {.cell-output-display}\n\n```{=html}\n
\n\n07:00\n
\n```\n\n:::\n:::\n",
6 | "supporting": [],
7 | "filters": [
8 | "rmarkdown/pagebreak.lua"
9 | ],
10 | "includes": {
11 | "include-in-header": [
12 | "\n\n"
13 | ],
14 | "include-after-body": [
15 | "\n\n\n"
16 | ]
17 | },
18 | "engineDependencies": {},
19 | "preserve": {},
20 | "postProcess": true
21 | }
22 | }
--------------------------------------------------------------------------------
/_freeze/6-summary/6-summary/execute-results/html.json:
--------------------------------------------------------------------------------
1 | {
2 | "hash": "993cdb0e4530329379acf85c989fa40e",
3 | "result": {
4 | "engine": "knitr",
5 | "markdown": "---\ntitle: \"🏁 Summary {width=5em}\"\nformat: revealjs\n---\n\n\n\n## Learning objective 1\n\n**Understand what parameterized reporting is and when it is useful.**\n\n. . .\n\n**Like very fancy custom functions:**\n\n::: incremental\n\n- Function → `.qmd` template\n\n- Input → parameters\n\n- Output → rendered reports\n:::\n\n. . . \n\n**Useful for creating variations of the same report:**\n\n- Spatial: country, state, county, or city\n\n- Temporal: year, month or other time period\n\n- Anything you can filter by: breeds, species, diseases, water bodies, customers, trials, etc.\n\n. . .\n\n::: callout-note\nWe only covered reports, but you can also parameterize `revealjs` presentations! See this [Jumping Rivers blog post](https://www.jumpingrivers.com/blog/r-parameterised-presentations-quarto/) about it.\n:::\n\n## Learning objective 2a\n\n**Convert a Quarto document into a parameterized template.**\n\n::: incremental\n- Include default `params:` in YAML\n \n- Replace hard-coded values with `params$pet_type`\n\n - **YAML**: \n \n\n\n ::: {.cell}\n \n ```{.yaml .cell-code}\n ---\n title: \"Report about `r params$pet_type`\"\n params:\n pet_type: \"cats\"\n ---\n ```\n :::\n\n\n \n - **Inline R code**: \n \n\n\n ::: {.cell}\n \n ```{.markdown .cell-code}\n I like **`r params$pet_type`**.\n ```\n :::\n\n\n \n - **Code chunks**: \n \n ``` r\n pets |> \n dplyr::filter(pet_type == params$pet_type)\n ```\n:::\n\n## Learning objective 2b\n\n**Render all variations of the report at once using [{quarto}](https://quarto-dev.github.io/quarto-r/) and [{purrr}](https://purrr.tidyverse.org/).**\n\n::: {.fragment}\n1. Get all unique parameter combinations into a dataframe:\n\n\n\n::: {.cell}\n\n:::\n\n::: {.cell}\n\n```{.r .cell-code}\nhead(pet_reports, 2)\n```\n\n::: {.cell-output-display}\n