-
Notifications
You must be signed in to change notification settings - Fork 1
/
render.Rmd
78 lines (59 loc) · 2.85 KB
/
render.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
---
title: "Render your reports"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Render your reports}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
Render a single report at a time with the RStudio user interface, or
programmatically render all reports (for all producers and in all formats) with
the `render_reports.R` script.
## Using RStudio
To generate and preview the report with the default parameters[^1], use the
`Render` button or keyboard shortcut (`Ctrl + Shift + K`). Use this workflow to
quickly iterate on content and style. For HTML reports, check the
`Render on Save` option to automatically update the preview whenever you save
the document.
[^1]: The default parameters are the `producer_id` and `year` combination that
was set in the YAML header of `01_producer-report.qmd.`
![](../man/figures/render.png){width="80%"
fig-alt="RStudio Quarto Render button with a dropdown for HTML and MS Word. Render on Save option is checked."}
The [**Render the example
reports**](https://wa-department-of-agriculture.github.io/soils/articles/render-example.html)
tutorial provides additional details on rendering reports with the RStudio user
interface.
## Using `render_reports.R`
`render-reports.R` creates a dataframe and then uses `purrr::pwalk()` to iterate
over each row, rendering all reports in both HTML and MS Word formats. After
rendering, all reports are moved to a folder called `reports` in the project
directory.
1. Edit `render_reports.R` to read in the same dataset in the `load-data` chunk
of `01_producer-report.qmd`. For example, if your dataset is called
`my-data.csv`, replace `washi-data.csv` with `my-data.csv` in Line 11.
2. Click `Source` to run this script and generate all reports in all formats at
once.
![](../man/figures/render-reports.png){fig-alt="RStudio screenshot of `render-reports.R` script with box and arrow instructing the user to replace `washi-data.csv` with the name of the user's data file. A second box and arrow instructs the user to click the Source button to run the script and generate all reports."}
**Optionally**, to render reports for only a subset of producers, filter the
dataframe to include only this subset. The last line of the below code block
demonstrates how to filter the data to three specific producers.
```{r}
#| eval: false
# EDIT: Replace `washi-data.csv` with the name of the same dataset used in
# 01_producer-report.qmd.
data <- read.csv(
here::here("data/washi-data.csv"),
check.names = FALSE,
encoding = "UTF-8"
) |>
dplyr::filter(producer_id %in% c("WUY05", "RHM05", "ENR07"))
```
## Video demo of `render-reports.R`
<iframe src="https://drive.google.com/file/d/1J4NpFpV2iv6f3S4PcS5Hw1jA3KPZgzIU/preview" width="640" height="360" allow="autoplay">
</iframe>