Skip to content

Commit e0a05c0

Browse files
committed
fix: include Inf as possible time_type in error message
1 parent 1d7b46f commit e0a05c0

File tree

3 files changed

+20
-20
lines changed

3 files changed

+20
-20
lines changed

R/utils.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -821,22 +821,22 @@ validate_slide_window_arg <- function(arg, time_type, arg_name = rlang::caller_a
821821
if (!identical(arg, Inf)) {
822822
if (time_type == "day") {
823823
if (!test_int(arg, lower = 0L) && !(inherits(arg, "difftime") && units(arg) == "days")) {
824-
cli_abort("Expected `{arg_name}` to be a difftime with units in days or a non-negative integer.")
824+
cli_abort("Expected `{arg_name}` to be a difftime with units in days, a non-negative integer, or Inf.")
825825
}
826826
} else if (time_type == "week") {
827827
if (!(inherits(arg, "difftime") && units(arg) == "weeks")) {
828-
cli_abort("Expected `{arg_name}` to be a difftime with units in weeks.")
828+
cli_abort("Expected `{arg_name}` to be a difftime with units in weeks or Inf.")
829829
}
830830
} else if (time_type == "yearmonth") {
831831
if (!test_int(arg, lower = 0L) || inherits(arg, "difftime")) {
832-
cli_abort("Expected `{arg_name}` to be a non-negative integer.")
832+
cli_abort("Expected `{arg_name}` to be a non-negative integer or Inf.")
833833
}
834834
} else if (time_type == "integer") {
835835
if (!test_int(arg, lower = 0L) || inherits(arg, "difftime")) {
836-
cli_abort("Expected `{arg_name}` to be a non-negative integer.")
836+
cli_abort("Expected `{arg_name}` to be a non-negative integer or Inf.")
837837
}
838838
} else {
839-
cli_abort("Expected `{arg_name}` to be Inf, an appropriate a difftime, or a non-negative integer.")
839+
cli_abort("Expected `{arg_name}` to be an appropriate a difftime, a non-negative integer, or Inf.")
840840
}
841841
}
842842
}

tests/testthat/test-epi_slide.R

+13-13
Original file line numberDiff line numberDiff line change
@@ -107,23 +107,23 @@ test_that("Test errors/warnings for discouraged features", {
107107
test_that("Both `before` and `after` must be non-NA, non-negative, integer-compatible", {
108108
expect_error(
109109
epi_slide(grouped, f, before = -1L, ref_time_values = test_date + 2L),
110-
"Expected `before` to be a difftime with units in days or a non-negative integer."
110+
"Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
111111
)
112112
expect_error(
113113
epi_slide(grouped, f, after = -1L, ref_time_values = test_date + 2L),
114-
"Expected `after` to be a difftime with units in days or a non-negative integer."
114+
"Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
115115
)
116116
expect_error(epi_slide(grouped, f, before = "a", after = days_dt, ref_time_values = test_date + 2L),
117-
regexp = "Expected `before` to be a difftime with units in days or a non-negative integer."
117+
regexp = "Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
118118
)
119119
expect_error(epi_slide(grouped, f, before = days_dt, after = "a", ref_time_values = test_date + 2L),
120-
regexp = "Expected `after` to be a difftime with units in days or a non-negative integer."
120+
regexp = "Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
121121
)
122122
expect_error(epi_slide(grouped, f, before = 0.5, after = days_dt, ref_time_values = test_date + 2L),
123-
regexp = "Expected `before` to be a difftime with units in days or a non-negative integer."
123+
regexp = "Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
124124
)
125125
expect_error(epi_slide(grouped, f, before = days_dt, after = 0.5, ref_time_values = test_date + 2L),
126-
regexp = "Expected `after` to be a difftime with units in days or a non-negative integer."
126+
regexp = "Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
127127
)
128128
expect_error(
129129
epi_slide(grouped, f, before = NA, after = 1L, ref_time_values = test_date + 2L),
@@ -136,27 +136,27 @@ test_that("Both `before` and `after` must be non-NA, non-negative, integer-compa
136136

137137
expect_error(
138138
epi_slide_mean(grouped, col_names = value, before = -1L, ref_time_values = test_date + 2L),
139-
"Expected `before` to be a difftime with units in days or a non-negative integer."
139+
"Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
140140
)
141141
expect_error(
142142
epi_slide_mean(grouped, col_names = value, after = -1L, ref_time_values = test_date + 2L),
143-
"Expected `after` to be a difftime with units in days or a non-negative integer."
143+
"Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
144144
)
145145
expect_error(
146146
epi_slide_mean(grouped, col_names = value, before = "a", ref_time_values = test_date + 2L),
147-
regexp = "Expected `before` to be a difftime with units in days or a non-negative integer."
147+
regexp = "Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
148148
)
149149
expect_error(
150150
epi_slide_mean(grouped, col_names = value, after = "a", ref_time_values = test_date + 2L),
151-
regexp = "Expected `after` to be a difftime with units in days or a non-negative integer."
151+
regexp = "Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
152152
)
153153
expect_error(
154154
epi_slide_mean(grouped, col_names = value, before = 0.5, ref_time_values = test_date + 2L),
155-
regexp = "Expected `before` to be a difftime with units in days or a non-negative integer."
155+
regexp = "Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
156156
)
157157
expect_error(
158158
epi_slide_mean(grouped, col_names = value, after = 0.5, ref_time_values = test_date + 2L),
159-
regexp = "Expected `after` to be a difftime with units in days or a non-negative integer."
159+
regexp = "Expected `after` to be a difftime with units in days, a non-negative integer, or Inf."
160160
)
161161
expect_error(
162162
epi_slide_mean(grouped, col_names = value, before = NA, after = days_dt, ref_time_values = test_date + 2L),
@@ -444,7 +444,7 @@ test_that("`ref_time_values` + `all_rows = TRUE` works", {
444444
) %>%
445445
epi_slide_mean(
446446
value,
447-
before = 6 * days_dt, names_sep = NULL, na.rm = TRUE
447+
before = 6 * days_dt, na.rm = TRUE
448448
),
449449
basic_mean_result %>%
450450
rename(slide_value_value = slide_value)

tests/testthat/test-epix_slide.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@ test_that("epix_slide `before` validation works", {
173173
)
174174
expect_error(
175175
xx %>% epix_slide(f = ~ sum(.x$binary), before = -1),
176-
"Expected `before` to be a difftime with units in days or a non-negative integer."
176+
"Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
177177
)
178178
expect_error(
179179
xx %>% epix_slide(f = ~ sum(.x$binary), before = 1.5),
180-
"Expected `before` to be a difftime with units in days or a non-negative integer."
180+
"Expected `before` to be a difftime with units in days, a non-negative integer, or Inf."
181181
)
182182
# These `before` values should be accepted:
183183
expect_no_error(xx %>% epix_slide(f = ~ sum(.x$binary), before = 0))

0 commit comments

Comments
 (0)