1-
1+ # ' Convert time slide function to a simple hop function
22# '
33# ' @examples
4- # ' time_slide_to_simple_hopper (as_time_slide_computation(~ .x[1L,]),
4+ # ' time_slide_to_simple_hop (as_time_slide_computation(~ .x[1L, ]),
55# ' .before_n_steps = 2L, .after_n_steps = 0L
66# ' )(
77# ' tibble(time_value = 1:5, value = 1:5),
88# ' tibble(geo_value = 1),
99# ' 3:4
1010# ' )
1111# '
12- time_slide_to_simple_hopper <- function (.slide_comp , ... , .before_n_steps , .after_n_steps ) {
13- function (grp_data , grp_key ,ref_inds ) {
12+ time_slide_to_simple_hop <- function (.slide_comp , ... , .before_n_steps , .after_n_steps ) {
13+ function (grp_data , grp_key , ref_inds ) {
1414 available_ref_time_values <- vec_slice(grp_data $ time_value , ref_inds )
1515 i <<- 0L
1616 wrapped_slide_comp <- function (.x , .group_key , ... ) {
@@ -54,23 +54,23 @@ time_slide_to_simple_hopper <- function(.slide_comp, ..., .before_n_steps, .afte
5454 cli_abort(
5555 " epi_slide: slide computations must always return either data frames
5656 or unnamed vectors (as determined by the vctrs package)." ,
57- class = " epiprocess__invalid_slide_comp_value"
57+ class = " epiprocess__invalid_slide_comp_value"
5858 )
5959 }
6060 # Returned values must all be the same type.
6161 if (length(return_types ) != 1L ) {
6262 cli_abort(
6363 " epi_slide: slide computations must always return either a data.frame or a vector (as determined by the
6464 vctrs package), but not a mix of the two." ,
65- class = " epiprocess__invalid_slide_comp_value"
65+ class = " epiprocess__invalid_slide_comp_value"
6666 )
6767 }
6868 # Returned values must always be a scalar vector or a data frame with one row.
6969 if (any(vctrs :: list_sizes(slide_values_list ) != 1L )) {
7070 cli_abort(
7171 " epi_slide: slide computations must return a single element (e.g. a scalar value, a single data.frame row,
7272 or a list)." ,
73- class = " epiprocess__invalid_slide_comp_value"
73+ class = " epiprocess__invalid_slide_comp_value"
7474 )
7575 }
7676 # Flatten the output list. This will also error if the user's slide function
@@ -81,23 +81,20 @@ time_slide_to_simple_hopper <- function(.slide_comp, ..., .before_n_steps, .afte
8181 }
8282}
8383
84- # TODO hopper -> skipper?
85-
8684# TODO simplify to just trailing and put shift elsewhere?
8785# '
88- # ' upstream_slide_to_simple_hopper (frollmean, .in_colnames = "value", .out_colnames = "slide_value", .before_n_steps = 1L, .after_n_steps = 0L)(
86+ # ' upstream_slide_to_simple_hop (frollmean, .in_colnames = "value", .out_colnames = "slide_value", .before_n_steps = 1L, .after_n_steps = 0L)(
8987# ' tibble(time_value = 1:5, value = 1:5),
9088# ' tibble(geo_value = 1),
9189# ' 3:4
9290# ' )
93- upstream_slide_to_simple_hopper <- function (.f , ... , .in_colnames , .out_colnames , .before_n_steps , .after_n_steps ) {
91+ upstream_slide_to_simple_hop <- function (.f , ... , .in_colnames , .out_colnames , .before_n_steps , .after_n_steps ) {
9492 f_info <- upstream_slide_f_info(.f , ... )
9593 in_colnames <- .in_colnames
9694 out_colnames <- .out_colnames
9795 f_from_package <- f_info $ from_package
9896 # TODO move .before_n_steps, .after_n_steps to args of this function?
99- switch (
100- f_from_package ,
97+ switch (f_from_package ,
10198 data.table = if (.before_n_steps == Inf ) {
10299 if (.after_n_steps != 0L ) {
103100 stop(" .before_n_steps only supported with .after_n_steps = 0" )
@@ -124,7 +121,7 @@ upstream_slide_to_simple_hopper <- function(.f, ..., .in_colnames, .out_colnames
124121 }
125122 },
126123 slider =
127- # TODO Inf checks?
124+ # TODO Inf checks?
128125 function (grp_data , grp_key , ref_inds ) {
129126 for (col_i in seq_along(in_colnames )) {
130127 grp_data [[out_colnames [[col_i ]]]] <- f_dots_baked(grp_data [[in_colnames [[col_i ]]]], before = .before_n_steps , after = .after_n_steps )
@@ -141,6 +138,6 @@ upstream_slide_to_simple_hopper <- function(.f, ..., .in_colnames, .out_colnames
141138
142139# TODO grp_ -> ek_ ?
143140
144- # TODO "hopper " -> "hop"
141+ # TODO "simple_hop " -> "skip"/"jump"?
145142
146143# TODO tacking on output columns -> outputting output columns
0 commit comments