Skip to content

Commit c2ed117

Browse files
committed
perf(epi_slide): avoid tibble() overhead in loop
1 parent 872dc36 commit c2ed117

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

R/slide.R

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ epi_slide <- function(
309309
...,
310310
.keep = TRUE
311311
) %>%
312-
{vec_rbind(!!!.)} %>%
312+
{
313+
vec_rbind(!!!.)
314+
} %>%
313315
`[`(.$.real, names(.) != ".real") %>%
314316
arrange_col_canonical() %>%
315317
group_by(!!!.x_orig_groups)
@@ -345,13 +347,14 @@ epi_slide_one_group <- function(
345347
.data_group, # (epi_df; epi_slide uses .keep = TRUE)
346348
vec_cbind( # (tibble -> vec_rbind produces tibble)
347349
.group_key,
348-
tibble(
350+
new_tibble(vec_recycle_common(
349351
time_value = c(
350352
missing_times,
351353
.date_seq_list$pad_early_dates,
352354
.date_seq_list$pad_late_dates
353-
), .real = FALSE
354-
)
355+
),
356+
.real = FALSE
357+
))
355358
)
356359
# we should be adding time values of the same time_type (and shouldn't be
357360
# introducing duplicate epikeytime values); we can reclass without checks:
@@ -902,7 +905,10 @@ epi_slide_opt <- function(
902905
# first `before` and last `after` elements.
903906
.data_group <- vec_rbind(
904907
.data_group, # (tibble; epi_slide_opt uses .keep = FALSE)
905-
tibble(time_value = c(missing_times, pad_early_dates, pad_late_dates), .real = FALSE)
908+
new_tibble(vec_recycle_common(
909+
time_value = c(missing_times, pad_early_dates, pad_late_dates),
910+
.real = FALSE
911+
))
906912
) %>%
907913
`[`(vec_order(.$time_value), )
908914

0 commit comments

Comments
 (0)