Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
cbe166a
Use testthat edition 3
steffilazerte May 27, 2026
9787acb
Add mini samplers snapshots
steffilazerte May 27, 2026
f833b17
Clean up
steffilazerte May 27, 2026
dd7296c
Add more tests to fill out gibbs sampling
steffilazerte May 27, 2026
eb9ccfb
Convert snapshots to snapshot values - estimate_R()
steffilazerte May 28, 2026
a2f1e8f
Convert serialized snapshots to snapshot values - back-compatibility …
steffilazerte May 28, 2026
b422647
Add snapshot tests - walinga_teunis()
steffilazerte May 28, 2026
098cfe8
Update epi_shapshot_value() to recurse infinitely as needed
steffilazerte May 28, 2026
3f97e68
Add gibs draws specific tests
steffilazerte Jun 2, 2026
0ee26d7
Fix snapshots - don't randomize if not samping
steffilazerte Jun 2, 2026
f00e031
Check for class removed with custom snapshot
steffilazerte Jun 2, 2026
859c7e4
Update snapshots
steffilazerte Jun 2, 2026
57786c2
Fix lintr problems in test files
steffilazerte Jun 2, 2026
c3dc2d9
Update gibs_draws snaps
steffilazerte Jun 2, 2026
36fbdf9
Fix warnings in plot and vignette from size -> linewidth
steffilazerte Jun 2, 2026
b73dcfa
Quieten noisy tests after update to testthat edition 3
steffilazerte Jun 2, 2026
0ef8c9c
General test cleanup
steffilazerte Jun 2, 2026
0f09cae
Fix problem with snapshot differing on ubuntu?
steffilazerte Jun 2, 2026
876d0c4
Address finicky tests with withr::with_seed?
steffilazerte Jun 2, 2026
1a6b25c
Allow lower digits matches where problematic comparing macos
steffilazerte Jun 2, 2026
4743d00
Update truncated samplers snaps
steffilazerte Jun 2, 2026
13211e3
Skip on mac
steffilazerte Jun 2, 2026
e24eb36
Skip on mac where cannot compare randomness
steffilazerte Jun 2, 2026
51c537a
set seed early to fix samplers?
steffilazerte Jun 2, 2026
b97e752
Add missing samplers snaps
steffilazerte Jun 3, 2026
3ab6a7d
Fix doppleganger test paths
steffilazerte Jun 3, 2026
92a87fb
Skip fragile tests where necessary
steffilazerte Jun 3, 2026
f85463e
Correct test path in doppleganger
steffilazerte Jun 3, 2026
0593b22
Add tests for plots of wallinga_teunis results (fixes #204)
steffilazerte Jun 5, 2026
07444a5
Move incidence and incidence2 to suggests (fixes #241)
steffilazerte Jun 17, 2026
479c7f2
Add mocked tests to for installation check
steffilazerte Jun 17, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ BugReports: https://github.com/mrc-ide/EpiEstim/issues
Depends: R (>= 3.3.0)
Imports:
coarseDataTools (>= 0.6-4),
incidence (>= 1.7.0),
incidence2 (>= 2.6.4.9000),
ggplot2,
fitdistrplus,
coda,
Expand All @@ -42,7 +40,9 @@ Imports:
patchwork (>= 1.2.0),
rlang
Suggests:
testthat,
incidence (>= 1.7.0),
incidence2 (>= 2.6.4.9000),
testthat (>= 3.0.0),
utils,
vdiffr,
covr,
Expand All @@ -61,3 +61,4 @@ Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.3
VignetteBuilder: knitr
Remotes: reconverse/incidence2/pkg
Config/testthat/edition: 3
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# EpiEstim 3.0.1

- Moved incidence and incidence2 to suggests `walling_teunis()` and
`estimate_R()` will check for installations as required (fixes
[#241](https://github.com/mrc-ide/EpiEstim/issues/241))

# EpiEstim 3.0.0

## New features
Expand Down
7 changes: 7 additions & 0 deletions R/estimate_R.R
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,13 @@ estimate_R <- function(incid,
date_convention = NULL
) {

if(inherits(incid, "incidence")) {
rlang::check_installed("incidence", "to work with incidence data")
}
if(inherits(incid, "incidence2")) {
rlang::check_installed("incidence2", "to work with incidence2 data")
}

if (is.data.frame(incid) && "dates" %in% names(incid)) {
if (!all(diff(incid$dates) > 0)) {
stop("dates in incid must be in ascending order", call. = FALSE)
Expand Down
3 changes: 2 additions & 1 deletion R/plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
panel.border = element_blank(),
axis.line = element_line(
colour = "black",
size = 0.2
linewidth = 0.2
),
plot.title = element_text(
size = 12,
Expand All @@ -202,7 +202,7 @@

options_I$col <- "#5983AB"
} else {
if (plot_theme == "original") {

Check warning on line 205 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=205,col=5,[unnecessary_nesting_linter] Simplify this condition by using 'else if' instead of 'else { if.
theme_epiestim <- function() {
theme()
}
Expand All @@ -222,7 +222,7 @@
} else {
multiple_input <- TRUE
if (length(unique(vapply(x, function(e) nrow(e$R), integer(1)))) > 1) {
stop("R estimates cannot be plotted simulatneously because

Check warning on line 225 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=225,col=7,[condition_call_linter] Use stop(., call. = FALSE) not to display the call in an error message.
they are of different sizes, i.e. they were obtained using
t_start or t_end of different lengths")
}
Expand All @@ -234,9 +234,9 @@
options_R$col,
ceiling(length(x_list) / length(options_R$col))
)
options_R$col <- options_R$col[seq_len(length(x_list))]

Check warning on line 237 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=237,col=38,[seq_linter] Use seq_along(x) instead of seq_len(length(x)).
} else {
options_R$col <- options_R$col[seq_len(length(x_list))]

Check warning on line 239 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=239,col=38,[seq_linter] Use seq_along(x) instead of seq_len(length(x)).
}
}

Expand All @@ -248,7 +248,7 @@
method <- x$method
si_distr <- x$si_distr
incid <- data.frame(local = x$I_local, imported = x$I_imported)
T <- nrow(incid)

Check warning on line 251 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=251,col=3,[object_overwrite_linter] 'T' is an exported object from package 'base'. Avoid re-using such symbols.
if (!is.null(x$dates)) {
dates <- x$dates
} else {
Expand All @@ -264,6 +264,7 @@

what <- match.arg(what)
if (what %in% c("incid", "all")) {
rlang::check_installed("incidence", "to plot incidence data")
if (add_imported_cases) {
p1 <- plot(
incidence::as.incidence(incid,
Expand Down Expand Up @@ -315,13 +316,13 @@
options_R$xlim <- c(min(dates), max(dates) + 1)
}

df <- reshape2::melt(data.frame(

Check warning on line 319 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=319,col=9,[object_overwrite_linter] 'df' is an exported object from package 'stats'. Avoid re-using such symbols.
start = dates[t_start] - 0.5, end = dates[t_end] + 0.5, meanR = mean_posterior,
lower = quantile_0.025_posterior,
upper = quantile_0.975_posterior
), id.vars = c("meanR", "lower", "upper"))
df$group <- as.factor(rep(
seq_len(length(t_start)),

Check warning on line 325 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=325,col=11,[seq_linter] Use seq_along(x) instead of seq_len(length(x)).
dim(df)[1] / length(t_start)
))

Expand All @@ -348,7 +349,7 @@
lower = quantile_0.025_posterior,
upper = quantile_0.975_posterior
)
df <- df_tmp

Check warning on line 352 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=352,col=9,[object_overwrite_linter] 'df' is an exported object from package 'stats'. Avoid re-using such symbols.
id_tmp <- c("meanR", "lower", "upper")
id <- id_tmp

Expand All @@ -370,7 +371,7 @@
upper2 = quantile_0.975_posterior2
)
names(df_tmp2) <- paste0(names(df_tmp), i)
df <- cbind(df, df_tmp2)

Check warning on line 374 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=374,col=11,[object_overwrite_linter] 'df' is an exported object from package 'stats'. Avoid re-using such symbols.
id_tmp2 <- paste0(id, i)
id <- c(id, id_tmp2)
}
Expand All @@ -385,7 +386,7 @@
options_R$xlim <- c(min(dates), max(dates) + 1)
}

df <- reshape2::melt(df, id = id)

Check warning on line 389 in R/plot.R

View workflow job for this annotation

GitHub Actions / lint-changed-files

file=R/plot.R,line=389,col=9,[object_overwrite_linter] 'df' is an exported object from package 'stats'. Avoid re-using such symbols.
df$group <- as.factor(rep(
seq_len(length(t_start)),
dim(df)[1] / length(t_start)
Expand Down
40 changes: 35 additions & 5 deletions R/test_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@
#'
#' @noRd

epi_expect_doppelganger <- function(name, code, variant) {
epi_expect_doppelganger <- function(name, test, code, variant) {

testthat::skip_if_not_installed("vdiffr")

on_ci <- as.logical(Sys.getenv("CI", "false"))
no_snap <- !file.exists(
testthat::test_path(
"_snaps",
variant,
paste0(name, ".svg")
testthat::test_path("_snaps", variant, test, paste0(name, ".svg")
)
)
if (on_ci && no_snap) {
Expand All @@ -35,3 +32,36 @@ epi_expect_doppelganger <- function(name, code, variant) {
)
}

#' Custom snapshot utility function
#'
#' Creates mini snapshots by sampling `x` down to `n`. If `x` is a list, the
#' function recurses down the list sampling applies to all sub-items (which may
#' or may not be appropriate, depending on the situation). Also rounds to 8
#' digits to avoid mismatches in re-loading values with long trailing decimals.
#'
#' @param x Vector or list of vectors to take a snapshot of.
#' @param style Snapshot style (see `?testthat::snapshot_value()`)
#' @param n Numeric. Number of samples to keep
#'
#' @noRd
epi_snapshot_value <- function(x, style = "json2", n = 5, digits = 8) {

sample_x <- function(xx) {
# Recurse if this is still a list
if(is.list(xx)) return(lapply(xx, sample_x))

# Take random sample of points if less than n
if(!is.null(n) && length(xx) > n) {
set.seed(1) # TODO: could use withr::with_seed()
xx <- sample(xx, size = n)
}

# Round to avoid mismatches from truncated records
if(is.numeric(xx)) xx <- round(xx, digits = digits)
xx
}

x <- sample_x(x)

testthat::expect_snapshot_value(x, style = style)
}
4 changes: 4 additions & 0 deletions R/wallinga_teunis.R
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,8 @@ wallinga_teunis.incidence <- function(incid,
quiet = FALSE,
...) {

rlang::check_installed("incidence", "to work with incidence data")

## checks specific to incidence objects
if (as.integer(mean(incidence::get_interval(incid))) != 1L) {
msg <- sprintf(
Expand Down Expand Up @@ -457,6 +459,8 @@ wallinga_teunis.incidence2 <- function(incid,
quiet = FALSE,
...) {

rlang::check_installed("incidence2", "to work with incidence2 data")

## checks specific to incidence2 objects
dates <- incidence2::get_dates(incid)
interval <- incidence2::get_interval_duration(incid)
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# This file is part of the standard setup for testthat.
# It is recommended that you do not modify it.
#
# Where should you do additional test configuration?
# Learn more about the roles of various files in:
# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
# * https://testthat.r-lib.org/articles/special-files.html

library(testthat)
library(EpiEstim)

Expand Down
Binary file removed tests/testthat/Rplots.pdf
Binary file not shown.
Loading
Loading