9
9
# ' useful in realtime and pseudo-prospective forecasting for data where there is
10
10
# ' some delay between the day recorded and when that data is available.
11
11
# '
12
- # ' @param recipe A recipe object. The step will be added to the
13
- # ' sequence of operations for this recipe.
14
- # ' @param ... One or more selector functions to choose variables for this step.
15
- # ' See [recipes::selections()] for more details. Typically you will not need
16
- # ' to set this manually, as the necessary adjustments will be done for the
17
- # ' predictors and outcome.
18
12
# ' @param method a character. Determines the method by which the
19
13
# ' forecast handles latency. The options are:
20
14
# ' - `"extend_ahead"`: Lengthen the ahead so that forecasting from the last
52
46
# ' `forecast_date` is determined either via the `fixed_latency`, or is set to
53
47
# ' the `epi_df`'s `as_of` value if `fixed_latency` is also `NULL`.
54
48
# ' @param role For model terms created by this step, what analysis role should
55
- # ' they be assigned? `lag` is default a predictor while `ahead` is an outcome.
56
- # ' It should be correctly inferred and not need setting
57
- # ' @param trained A logical to indicate if the quantities for preprocessing have
58
- # ' been estimated.
59
- # ' @param columns A character string of column names to be adjusted; these
60
- # ' should be the original columns, and not the derived ones
49
+ # ' they be assigned? `lag` is a predictor while `ahead` is an outcome. It
50
+ # ' should be correctly inferred and not need setting
61
51
# ' @param default Determines what fills empty rows
62
52
# ' left by leading/lagging (defaults to NA).
63
- # ' @param skip A logical. Should the step be skipped when the
64
- # ' recipe is baked by [bake()]? While all operations are baked
65
- # ' when [prep()] is run, some operations may not be able to be
66
- # ' conducted on new data (e.g. processing the outcome variable(s)).
67
- # ' Care should be taken when using `skip = TRUE` as it may affect
68
- # ' the computations for subsequent operations.
69
- # ' @param id A unique identifier for the step
70
53
# ' @template step-return
54
+ # ' @inheritParams recipes::step_lag
71
55
# '
72
56
# ' @details The step assumes that the pipeline has already applied either
73
57
# ' `step_epi_ahead` or `step_epi_lag` depending on the value of `"method"`,
@@ -189,6 +173,7 @@ step_adjust_latency <-
189
173
shift_cols = relevant_shifts ,
190
174
default = default ,
191
175
keys = epi_keys(recipe ),
176
+ columns = columns ,
192
177
skip = skip ,
193
178
id = id
194
179
)
@@ -197,7 +182,7 @@ step_adjust_latency <-
197
182
198
183
step_adjust_latency_new <-
199
184
function (terms , role , trained , forecast_date , latency , shift_cols , time_type , default ,
200
- keys , method , epi_keys_checked , skip , id ) {
185
+ keys , method , epi_keys_checked , columns , skip , id ) {
201
186
step(
202
187
subclass = " adjust_latency" ,
203
188
terms = terms ,
@@ -210,6 +195,7 @@ step_adjust_latency_new <-
210
195
shift_cols = shift_cols ,
211
196
default = default ,
212
197
keys = keys ,
198
+ columns = columns ,
213
199
skip = skip ,
214
200
id = id
215
201
)
@@ -220,7 +206,7 @@ step_adjust_latency_new <-
220
206
# ' @importFrom glue glue
221
207
prep.step_adjust_latency <- function (x , training , info = NULL , ... ) {
222
208
# get the columns used, even if it's all of them
223
- terms_used <- x $ columns
209
+ terms_used <- x $ terms
224
210
if (length(terms_used ) == 0 ) {
225
211
terms_used <- info %> %
226
212
filter(role == " raw" ) %> %
@@ -274,6 +260,7 @@ prep.step_adjust_latency <- function(x, training, info = NULL, ...) {
274
260
keys = x $ keys ,
275
261
method = x $ method ,
276
262
epi_keys_checked = x $ epi_keys_checked ,
263
+ columns = recipes_eval_select(latency_cols $ original_name , training , info ),
277
264
skip = x $ skip ,
278
265
id = x $ id
279
266
)
@@ -301,14 +288,18 @@ print.step_adjust_latency <-
301
288
if (! is.null(x $ forecast_date )) {
302
289
conj <- " with forecast date"
303
290
extra_text <- x $ forecast_date
304
- } else if (! is.null(x $ shift_cols )) {
305
- conj <- " with latencies"
306
- extra_text <- x $ shift_cols
291
+ } else if (! is.null(x $ latency )) {
292
+ conj <- if (length(x $ latency == 1 )) {
293
+ " with latency"
294
+ } else {
295
+ " with latencies"
296
+ }
297
+ extra_text <- x $ latency
307
298
} else {
308
- conj <- " "
299
+ conj <- " with latency "
309
300
extra_text <- " set at train time"
310
301
}
311
- print_epi_step(terms , NULL , x $ trained , x $ method ,
302
+ print_epi_step(terms , terms , x $ trained , x $ method ,
312
303
conjunction = conj ,
313
304
extra_text = extra_text
314
305
)
0 commit comments