Skip to content

Commit e530cca

Browse files
committed
Merge branch 'dev' into djm/plotting
2 parents e4bebf2 + 944a562 commit e530cca

8 files changed

+76
-1
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: epipredict
22
Title: Basic epidemiology forecasting methods
3-
Version: 0.0.11
3+
Version: 0.0.12
44
Authors@R: c(
55
person("Daniel", "McDonald", , "[email protected]", role = c("aut", "cre")),
66
person("Ryan", "Tibshirani", , "[email protected]", role = "aut"),

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.0.x will indicat
44

55
# epipredict 0.1
66

7+
- `*_args_list()` functions now warn if `forecast_date + ahead != target_date`
78
- `layer_residual_quantiles()` will now error if any of the residual quantiles are NA
89
- add `check_enough_train_data` that will error if training data is too small
910
- added `check_enough_train_data` to `arx_forecaster`

R/arx_classifier.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,15 @@ arx_class_args_list <- function(
299299
arg_is_pos(check_enough_data_n, allow_null = TRUE)
300300
arg_is_chr(check_enough_data_epi_keys, allow_null = TRUE)
301301

302+
if (!is.null(forecast_date) && !is.null(target_date)) {
303+
if (forecast_date + ahead != target_date) {
304+
cli::cli_warn(c(
305+
"`forecast_date` + `ahead` must equal `target_date`.",
306+
i = "{.val {forecast_date}} + {.val {ahead}} != {.val {target_date}}."
307+
))
308+
}
309+
}
310+
302311
breaks <- sort(breaks)
303312
if (min(breaks) > -Inf) breaks <- c(-Inf, breaks)
304313
if (max(breaks) < Inf) breaks <- c(breaks, Inf)

R/arx_forecaster.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,15 @@ arx_args_list <- function(
260260
arg_is_pos(check_enough_data_n, allow_null = TRUE)
261261
arg_is_chr(check_enough_data_epi_keys, allow_null = TRUE)
262262

263+
if (!is.null(forecast_date) && !is.null(target_date)) {
264+
if (forecast_date + ahead != target_date) {
265+
cli::cli_warn(c(
266+
"`forecast_date` + `ahead` must equal `target_date`.",
267+
i = "{.val {forecast_date}} + {.val {ahead}} != {.val {target_date}}."
268+
))
269+
}
270+
}
271+
263272
max_lags <- max(lags)
264273
structure(
265274
enlist(

R/flatline_forecaster.R

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ flatline_args_list <- function(
130130
if (is.finite(n_training)) arg_is_pos_int(n_training)
131131
if (is.finite(nafill_buffer)) arg_is_pos_int(nafill_buffer, allow_null = TRUE)
132132

133+
if (!is.null(forecast_date) && !is.null(target_date)) {
134+
if (forecast_date + ahead != target_date) {
135+
cli::cli_warn(c(
136+
"`forecast_date` + `ahead` must equal `target_date`.",
137+
i = "{.val {forecast_date}} + {.val {ahead}} != {.val {target_date}}."
138+
))
139+
}
140+
}
141+
133142
structure(
134143
enlist(
135144
ahead,

tests/testthat/test-arx_args_list.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ test_that("arx_args checks inputs", {
2525

2626
expect_error(arx_args_list(n_training_min = "de"))
2727
expect_error(arx_args_list(epi_keys = 1))
28+
29+
expect_warning(arx_args_list(
30+
forecast_date = as.Date("2022-01-01"),
31+
target_date = as.Date("2022-01-03"),
32+
ahead = 1L
33+
))
2834
})
2935

3036
test_that("arx forecaster disambiguates quantiles", {

tests/testthat/test-arx_cargs_list.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,10 @@ test_that("arx_class_args checks inputs", {
1919

2020
expect_error(arx_class_args_list(n_training_min = "de"))
2121
expect_error(arx_class_args_list(epi_keys = 1))
22+
23+
expect_warning(arx_class_args_list(
24+
forecast_date = as.Date("2022-01-01"),
25+
target_date = as.Date("2022-01-03"),
26+
ahead = 1L
27+
))
2228
})
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
test_that("flatline_args_list checks inputs", {
2+
expect_s3_class(flatline_args_list(), c("flat_fcast", "alist"))
3+
expect_error(flatline_args_list(ahead = c(0, 4)))
4+
expect_error(flatline_args_list(n_training = c(28, 65)))
5+
6+
expect_error(flatline_args_list(ahead = -1))
7+
expect_error(flatline_args_list(ahead = 1.5))
8+
expect_error(flatline_args_list(n_training = -1))
9+
expect_error(flatline_args_list(n_training = 1.5))
10+
expect_error(flatline_args_list(lags = c(-1, 0)))
11+
expect_error(flatline_args_list(lags = list(c(1:5, 6.5), 2:8)))
12+
13+
expect_error(flatline_args_list(symmetrize = 4))
14+
expect_error(flatline_args_list(nonneg = 4))
15+
16+
expect_error(flatline_args_list(quantile_levels = -.1))
17+
expect_error(flatline_args_list(quantile_levels = 1.1))
18+
expect_type(flatline_args_list(quantile_levels = NULL), "list")
19+
20+
expect_error(flatline_args_list(target_date = "2022-01-01"))
21+
expect_identical(
22+
flatline_args_list(target_date = as.Date("2022-01-01"))$target_date,
23+
as.Date("2022-01-01")
24+
)
25+
26+
expect_error(flatline_args_list(n_training_min = "de"))
27+
expect_error(flatline_args_list(epi_keys = 1))
28+
29+
# Detect mismatched ahead and target_date - forecast_date difference
30+
expect_warning(flatline_args_list(
31+
forecast_date = as.Date("2022-01-01"),
32+
target_date = as.Date("2022-01-03"),
33+
ahead = 1L
34+
))
35+
})

0 commit comments

Comments
 (0)