6565# ' determined the time window for the current computation.
6666# '
6767# ' @importFrom lubridate days weeks
68- # ' @importFrom dplyr bind_rows group_map group_vars filter select
68+ # ' @importFrom dplyr group_map group_vars filter select
6969# ' @importFrom rlang .data .env !! enquos sym env missing_arg
7070# ' @export
7171# ' @seealso [`epi_slide_opt`] for optimized slide functions
@@ -309,7 +309,7 @@ epi_slide <- function(
309309 ... ,
310310 .keep = TRUE
311311 ) %> %
312- bind_rows() %> %
312+ {vec_rbind( !!! . )} %> %
313313 `[`(. $ .real , names(. ) != " .real" ) %> %
314314 arrange_col_canonical() %> %
315315 group_by(!!! .x_orig_groups )
@@ -341,9 +341,9 @@ epi_slide_one_group <- function(
341341 # time values, padding on the left and right as needed.
342342 all_dates <- .date_seq_list $ all_dates
343343 missing_times <- all_dates [! (all_dates %in% .data_group $ time_value )]
344- .data_group <- bind_rows (
345- .data_group ,
346- dplyr :: bind_cols(
344+ .data_group <- reclass(vec_rbind (
345+ .data_group , # (epi_df; epi_slide uses .keep = TRUE)
346+ vec_cbind( # (tibble -> vec_rbind produces tibble)
347347 .group_key ,
348348 tibble(
349349 time_value = c(
@@ -353,17 +353,19 @@ epi_slide_one_group <- function(
353353 ), .real = FALSE
354354 )
355355 )
356- ) %> %
356+ # we should be adding time values of the same time_type (and shouldn't be
357+ # introducing duplicate epikeytime values); we can reclass without checks:
358+ ), attr(.data_group , " metadata" )) %> %
357359 `[`(vec_order(. $ time_value ), )
358360
359361 # If the data group does not contain any of the reference time values, return
360- # the original .data_group without slide columns and let bind_rows at the end
362+ # the original .data_group without slide columns and let vec_rbind at the end
361363 # of group_modify handle filling the empty data frame with NA values.
362364 if (length(available_ref_time_values ) == 0L ) {
363365 if (.all_rows ) {
364366 return (.data_group )
365367 }
366- return (.data_group % > % filter( FALSE ) )
368+ return (.data_group [ 0 , ] )
367369 }
368370
369371 # Get stateful function that tracks ref_time_value per group and sends it to
@@ -608,7 +610,7 @@ get_before_after_from_window <- function(window_size, align, time_type) {
608610# ' - `{.f_abbr}` will be a character vector containing a short abbreviation
609611# ' for `.f` factoring in the input column type(s) for `.col_names`
610612# '
611- # ' @importFrom dplyr bind_rows mutate %>% arrange tibble select all_of
613+ # ' @importFrom dplyr mutate %>% arrange tibble select all_of
612614# ' @importFrom rlang enquo expr_label caller_arg quo_get_env
613615# ' @importFrom tidyselect eval_select
614616# ' @importFrom glue glue
@@ -898,8 +900,8 @@ epi_slide_opt <- function(
898900 # `frollmean` requires a full window to compute a result. Add NA values
899901 # to beginning and end of the group so that we get results for the
900902 # first `before` and last `after` elements.
901- .data_group <- bind_rows (
902- .data_group ,
903+ .data_group <- vec_rbind (
904+ .data_group , # (tibble; epi_slide_opt uses .keep = FALSE)
903905 tibble(time_value = c(missing_times , pad_early_dates , pad_late_dates ), .real = FALSE )
904906 ) %> %
905907 `[`(vec_order(. $ time_value ), )
0 commit comments