Skip to content

Commit def8f37

Browse files
committed
smaller suggestions: local tests passing again
1 parent 24663c2 commit def8f37

6 files changed

+12
-34
lines changed

R/step_adjust_latency.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ prep.step_adjust_latency <- function(x, training, info = NULL, ...) {
194194
# check that the shift amount isn't too extreme
195195
latency <- max(shift_cols$latency)
196196
time_type <- attributes(training)$metadata$time_type
197+
i_latency <- which.max(shift_cols$latency)
197198
if (
198199
(grepl("day", time_type) && (latency >= 10)) ||
199200
(grepl("week", time_type) && (latency >= 4)) ||
@@ -207,8 +208,8 @@ prep.step_adjust_latency <- function(x, training, info = NULL, ...) {
207208
"which is questionable for it's `time_type` of ",
208209
"{time_type}"
209210
),
210-
"i" = "input ahead: {shift_cols$shifts[[i_latency]]}",
211-
"i" = "shifted ahead: {shift_cols$effective_shift[[i_latency]]}",
211+
"i" = "input shift: {shift_cols$shifts[[i_latency]]}",
212+
"i" = "latency adjusted shift: {shift_cols$effective_shift[[i_latency]]}",
212213
"i" = "max_time = {max_time} -> as_of = {as_of}"
213214
))
214215
}

R/step_epi_shift.R

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,8 @@ step_epi_lag <-
7272
)
7373
)
7474
}
75-
latency_adjustment <- rlang::arg_match(latency_adjustment)
7675
arg_is_nonneg_int(lag)
77-
arg_is_chr_scalar(prefix, id, latency_adjustment)
76+
arg_is_chr_scalar(prefix, id)
7877
if (!is.null(columns)) {
7978
cli::cli_abort(c(
8079
"The `columns` argument must be `NULL`.",
@@ -91,7 +90,6 @@ step_epi_lag <-
9190
prefix = prefix,
9291
default = default,
9392
keys = epi_keys(recipe),
94-
latency_adjustment = latency_adjustment,
9593
columns = columns,
9694
skip = skip,
9795
id = id
@@ -112,12 +110,6 @@ step_epi_ahead <-
112110
trained = FALSE,
113111
prefix = "ahead_",
114112
default = NA,
115-
latency_adjustment = c(
116-
"None",
117-
"extend_ahead",
118-
"locf",
119-
"extend_lags"
120-
),
121113
columns = NULL,
122114
skip = FALSE,
123115
id = rand_id("epi_ahead")) {
@@ -131,9 +123,8 @@ step_epi_ahead <-
131123
i = "Did you perhaps pass an integer in `...` accidentally?"
132124
))
133125
}
134-
latency_adjustment <- rlang::arg_match(latency_adjustment)
135126
arg_is_nonneg_int(ahead)
136-
arg_is_chr_scalar(prefix, id, latency_adjustment)
127+
arg_is_chr_scalar(prefix, id)
137128
if (!is.null(columns)) {
138129
cli::cli_abort(c("The `columns` argument must be `NULL`.",
139130
i = "Use `tidyselect` methods to choose columns to lead."
@@ -149,7 +140,6 @@ step_epi_ahead <-
149140
prefix = prefix,
150141
default = default,
151142
keys = epi_keys(recipe),
152-
latency_adjustment = latency_adjustment,
153143
columns = columns,
154144
skip = skip,
155145
id = id
@@ -160,7 +150,7 @@ step_epi_ahead <-
160150

161151
step_epi_lag_new <-
162152
function(terms, role, trained, lag, prefix, default, keys,
163-
latency_adjustment, columns, skip, id) {
153+
columns, skip, id) {
164154
step(
165155
subclass = "epi_lag",
166156
terms = terms,
@@ -170,15 +160,14 @@ step_epi_lag_new <-
170160
prefix = prefix,
171161
default = default,
172162
keys = keys,
173-
latency_adjustment = latency_adjustment,
174163
columns = columns,
175164
skip = skip,
176165
id = id
177166
)
178167
}
179168

180169
step_epi_ahead_new <-
181-
function(terms, role, trained, ahead, prefix, default, keys, latency_adjustment,
170+
function(terms, role, trained, ahead, prefix, default, keys,
182171
columns, skip, id) {
183172
step(
184173
subclass = "epi_ahead",
@@ -188,7 +177,6 @@ step_epi_ahead_new <-
188177
ahead = ahead,
189178
prefix = prefix,
190179
default = default,
191-
latency_adjustment = latency_adjustment,
192180
keys = keys,
193181
columns = columns,
194182
skip = skip,
@@ -208,7 +196,6 @@ prep.step_epi_lag <- function(x, training, info = NULL, ...) {
208196
prefix = x$prefix,
209197
default = x$default,
210198
keys = x$keys,
211-
latency_adjustment = x$latency_adjustment,
212199
columns = recipes_eval_select(x$terms, training, info),
213200
skip = x$skip,
214201
id = x$id
@@ -225,7 +212,6 @@ prep.step_epi_ahead <- function(x, training, info = NULL, ...) {
225212
prefix = x$prefix,
226213
default = x$default,
227214
keys = x$keys,
228-
latency_adjustment = x$latency_adjustment,
229215
columns = recipes_eval_select(x$terms, training, info),
230216
skip = x$skip,
231217
id = x$id

R/utils-latency.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ get_shifted_column_tibble <- function(
101101
mutate(
102102
new_name = adjust_name(prefix, original_name, effective_shift)
103103
)
104-
info <- shift_cols %>% select(variable, type, role)
104+
info <- info %>% select(variable, type, role)
105105
shift_cols <- left_join(shift_cols, info, by = join_by(original_name == variable))
106106
if (length(unique(shift_cols$role)) != 1) {
107107
cli::cli_abort("not all roles are the same!",
@@ -138,7 +138,7 @@ set_asof <- function(new_data, info) {
138138
as_of <- attributes(new_data)$metadata$as_of
139139
max_time <- max(time_values)
140140
# make sure the as_of is sane
141-
if (!inherits(as_of, class(time_values))) {
141+
if (!inherits(as_of, class(time_values)) & !inherits(as_of, "POSIXt")) {
142142
cli::cli_abort(glue::glue(
143143
"the data matrix `as_of` value is {as_of}, ",
144144
"and not a valid `time_type` with type ",

man/step_epi_shift.Rd

Lines changed: 0 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-step_adjust_latency.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ test_that("epi_adjust_latency correctly extends the lags", {
3434
# the as_of on x is today's date, which is >970 days in the future
3535
# also, there's no data >970 days in the past, so it gets an error trying to
3636
# fit on no data
37-
expect_error(expect_warning(fit5 <- slm_fit(r5)))
37+
expect_error(expect_warning(fit5 <- slm_fit(r5), regexp = "The shift has been adjusted by 1022"), class = "simpleError")
3838

3939
# now trying with the as_of a reasonable distance in the future
4040
fit5 <- slm_fit(r5, data = real_x)
41+
4142
expect_equal(
4243
names(fit5$pre$mold$predictors),
4344
c(

tests/testthat/test-utils_latency.R

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ old_data <- tibble(
88
tmp_death_rate = atan(0.1 * 1:200) + cos(5 * 1:200) + 1
99
) %>%
1010
as_epi_df(as_of = as_of)
11-
old_data %>% tail()
1211
keys <- c("time_value", "geo_value")
13-
old_data <- shift_cols %>%
12+
old_data <- old_data %>%
1413
full_join(epi_shift_single(
1514
old_data, "tmp_death_rate", 1, "death_rate", keys
1615
), by = keys) %>%

0 commit comments

Comments
 (0)