@@ -165,7 +165,7 @@ step_climate <-
165
165
arg_is_lgl_scalar(skip )
166
166
167
167
time_aggr <- switch (time_type ,
168
- epiweek = lubridate :: epiweek , week = lubridate :: week ,
168
+ epiweek = lubridate :: epiweek , week = lubridate :: isoweek ,
169
169
month = lubridate :: month , day = lubridate :: yday )
170
170
171
171
recipes :: add_step(
@@ -243,11 +243,15 @@ prep.step_climate <- function(x, training, info = NULL, ...) {
243
243
modulus <- switch (x $ time_type , epiweek = 53L , week = 53L , month = 12L , day = 365L )
244
244
245
245
fn <- switch (x $ center_method ,
246
- mean = function (x , w ) weighted.mean(x , w , na.rm = TRUE ),
246
+ mean = function (x , w ) stats :: weighted.mean(x , w , na.rm = TRUE ),
247
247
median = function (x , w ) median(x , na.rm = TRUE ))
248
248
249
249
climate_table <- training %> %
250
- mutate(.idx = x $ time_aggr(time_value ), .weights = wts ) %> %
250
+ mutate(
251
+ .idx = x $ time_aggr(time_value ), .weights = wts ,
252
+ .idx = (.idx - x $ forecast_ahead ) %% modulus ,
253
+ .idx = dplyr :: case_when(.idx == 0 ~ modulus , TRUE ~ .idx )
254
+ ) %> %
251
255
select(.idx , .weights , all_of(c(col_names , x $ epi_keys ))) %> %
252
256
tidyr :: pivot_longer(all_of(unname(col_names ))) %> %
253
257
dplyr :: reframe(
@@ -279,14 +283,9 @@ prep.step_climate <- function(x, training, info = NULL, ...) {
279
283
}
280
284
281
285
282
-
283
286
# ' @export
284
287
bake.step_climate <- function (object , new_data , ... ) {
285
- climate_table <- object $ climate_table %> %
286
- mutate(
287
- .idx = (.idx - object $ forecast_ahead ) %% object $ modulus ,
288
- .idx = dplyr :: case_when(.idx == 0 ~ object $ modulus , TRUE ~ .idx )
289
- )
288
+ climate_table <- object $ climate_table
290
289
new_data %> %
291
290
mutate(.idx = object $ time_aggr(time_value )) %> %
292
291
left_join(climate_table , by = c(" .idx" , object $ epi_keys )) %> %
0 commit comments