Skip to content

Commit 6f1891d

Browse files
committed
feat: add vignette snapshots
1 parent e74b7e7 commit 6f1891d

File tree

13 files changed

+4996
-50
lines changed

13 files changed

+4996
-50
lines changed

tests/testthat/_snaps/vignette-snapshot/advanced.html

Lines changed: 824 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/advanced.new.html

Lines changed: 825 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/aggregation.html

Lines changed: 613 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/archive.html

Lines changed: 699 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/archive.new.html

Lines changed: 696 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/epiprocess.html

Lines changed: 672 additions & 0 deletions
Large diffs are not rendered by default.

tests/testthat/_snaps/vignette-snapshot/slide.html

Lines changed: 614 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Vignettes that use epi_archives or epi_dfs.
2+
vignettes <- paste0(here::here("vignettes/"), c(
3+
"advanced.Rmd",
4+
"aggregation.Rmd",
5+
"archive.Rmd",
6+
"epiprocess.Rmd",
7+
"slide.Rmd"
8+
))
9+
for (input_file in vignettes) {
10+
test_that(paste0("snapshot vignette ", basename(input_file)), {
11+
# skip("Skipping snapshot tests by default, as they are slow.")
12+
output_file <- sub("\\.Rmd$", ".html", input_file)
13+
withr::with_file(output_file, {
14+
devtools::build_rmd(input_file)
15+
expect_snapshot_file(output_file)
16+
})
17+
})
18+
}

vignettes/advanced.Rmd

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ vignette: >
99

1010
In this vignette, we discuss how to use the sliding functionality in the
1111
`epiprocess` package with less common grouping schemes or with computations that
12-
have advanced output structures.
13-
The output of a slide computation should either be an atomic value/vector, or a
14-
data frame. This data frame can have multiple columns, multiple rows, or both.
12+
have advanced output structures. The output of a slide computation should either
13+
be an atomic value/vector, or a data frame. This data frame can have multiple
14+
columns, multiple rows, or both.
1515

1616
During basic usage (e.g., when all optional arguments are set to their defaults):
1717

1818
* `epi_slide(edf, <computation>, .....)`:
19-
2019
* keeps **all** columns of `edf`, adds computed column(s)
2120
* outputs **one row per row in `edf`** (recycling outputs from
2221
computations appropriately if there are multiple time series bundled
@@ -26,9 +25,7 @@ During basic usage (e.g., when all optional arguments are set to their defaults)
2625
`dplyr::arrange(time_value, .by_group = TRUE)`**
2726
* outputs an **`epi_df`** if the required columns are present, otherwise a
2827
tibble
29-
3028
* `epix_slide(ea, <computation>, .....)`:
31-
3229
* keeps **grouping and `time_value`** columns of `ea`, adds computed
3330
column(s)
3431
* outputs **any number of rows** (computations are allowed to output any
@@ -40,6 +37,7 @@ During basic usage (e.g., when all optional arguments are set to their defaults)
4037
* outputs a **tibble**
4138

4239
These differences in basic behavior make some common slide operations require less boilerplate:
40+
4341
* predictors and targets calculated with `epi_slide` are automatically lined up
4442
with each other and with the signals from which they were calculated; and
4543
* computations for an `epix_slide` can output data frames with any number of
@@ -84,13 +82,14 @@ simple synthetic example.
8482
```{r message = FALSE}
8583
library(epiprocess)
8684
library(dplyr)
85+
set.seed(123)
8786
8887
edf <- tibble(
8988
geo_value = rep(c("ca", "fl", "pa"), each = 3),
9089
time_value = rep(seq(as.Date("2020-06-01"), as.Date("2020-06-03"), by = "day"), length.out = length(geo_value)),
9190
x = seq_along(geo_value) + 0.01 * rnorm(length(geo_value)),
9291
) %>%
93-
as_epi_df()
92+
as_epi_df(as_of = as.Date("2024-03-20"))
9493
9594
# 2-day trailing average, per geo value
9695
edf %>%
@@ -338,7 +337,7 @@ library(data.table)
338337
library(ggplot2)
339338
theme_set(theme_bw())
340339
341-
x <- archive_cases_dv_subset_2$DT %>%
340+
x <- archive_cases_dv_subset$DT %>%
342341
filter(geo_value %in% c("ca", "fl")) %>%
343342
as_epi_archive(compactify = FALSE)
344343
```
@@ -525,10 +524,7 @@ separate ARX model on each state. As in the archive vignette, we can see a
525524
difference between version-aware (right column) and -unaware (left column)
526525
forecasting, as well.
527526

528-
529527
## Attribution
530528
The `case_rate_7d_av` data used in this document is a modified part of the [COVID-19 Data Repository by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University](https://github.com/CSSEGISandData/COVID-19) as [republished in the COVIDcast Epidata API](https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/jhu-csse.html). This data set is licensed under the terms of the [Creative Commons Attribution 4.0 International license](https://creativecommons.org/licenses/by/4.0/) by the Johns Hopkins University on behalf of its Center for Systems Science in Engineering. Copyright Johns Hopkins University 2020.
531529

532530
The `percent_cli` data is a modified part of the [COVIDcast Epidata API Doctor Visits data](https://cmu-delphi.github.io/delphi-epidata/api/covidcast-signals/doctor-visits.html). This dataset is licensed under the terms of the [Creative Commons Attribution 4.0 International license](https://creativecommons.org/licenses/by/4.0/). Copyright Delphi Research Group at Carnegie Mellon University 2020.
533-
534-

vignettes/aggregation.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ x <- pub_covidcast(
3434
) %>%
3535
select(geo_value, time_value, cases = value) %>%
3636
full_join(y, by = "geo_value") %>%
37-
as_epi_df()
37+
as_epi_df(as_of = as.Date("2024-03-20"))
3838
```
3939

4040
The data contains 16,212 rows and 5 columns.
@@ -192,7 +192,7 @@ running `epi_slide()` on the zero-filled data brings these trailing averages
192192

193193
```{r}
194194
xt %>%
195-
as_epi_df() %>%
195+
as_epi_df(as_of = as.Date("2024-03-20")) %>%
196196
group_by(geo_value) %>%
197197
epi_slide(cases_7dav = mean(cases), before = 6) %>%
198198
ungroup() %>%
@@ -203,7 +203,7 @@ xt %>%
203203
print(n = 7)
204204
205205
xt_filled %>%
206-
as_epi_df() %>%
206+
as_epi_df(as_of = as.Date("2024-03-20")) %>%
207207
group_by(geo_value) %>%
208208
epi_slide(cases_7dav = mean(cases), before = 6) %>%
209209
ungroup() %>%

0 commit comments

Comments
 (0)