@@ -122,8 +122,7 @@ epi_slide <- function(
122
122
assert_class(.x , " epi_df" )
123
123
if (checkmate :: test_class(.x , " grouped_df" )) {
124
124
expected_group_keys <- .x %> %
125
- key_colnames() %> %
126
- kill_time_value() %> %
125
+ key_colnames(exclude = " time_value" ) %> %
127
126
sort()
128
127
if (! identical(.x %> % group_vars() %> % sort(), expected_group_keys )) {
129
128
cli_abort(
@@ -134,12 +133,11 @@ epi_slide <- function(
134
133
)
135
134
}
136
135
} else {
137
- .x <- group_epi_df(.x )
136
+ .x <- group_epi_df(.x , exclude = " time_value " )
138
137
}
139
138
if (nrow(.x ) == 0L ) {
140
139
return (.x )
141
140
}
142
-
143
141
# If `.f` is missing, interpret ... as an expression for tidy evaluation
144
142
if (missing(.f )) {
145
143
used_data_masking <- TRUE
@@ -191,6 +189,20 @@ epi_slide <- function(
191
189
192
190
assert_logical(.all_rows , len = 1 )
193
191
192
+ # Check for duplicated time values within groups
193
+ duplicated_time_values <- .x %> %
194
+ group_epi_df() %> %
195
+ filter(dplyr :: n() > 1 ) %> %
196
+ ungroup()
197
+ if (nrow(duplicated_time_values ) > 0 ) {
198
+ bad_data <- capture.output(duplicated_time_values )
199
+ cli_abort(
200
+ " as_epi_df: some groups in a resulting dplyr computation have duplicated time values.
201
+ epi_df requires a unique time_value per group." ,
202
+ body = c(" Sample groups:" , bad_data )
203
+ )
204
+ }
205
+
194
206
# Begin handling completion. This will create a complete time index between
195
207
# the smallest and largest time values in the data. This is used to ensure
196
208
# that the slide function is called with a complete window of data. Each slide
@@ -241,7 +253,7 @@ epi_slide <- function(
241
253
.keep = TRUE
242
254
) %> %
243
255
bind_rows() %> %
244
- filter(.data $ . real ) %> %
256
+ filter(.real ) %> %
245
257
select(- .real ) %> %
246
258
arrange_col_canonical() %> %
247
259
group_by(!!! .x_groups )
@@ -275,11 +287,16 @@ epi_slide_one_group <- function(
275
287
missing_times <- all_dates [! (all_dates %in% .data_group $ time_value )]
276
288
.data_group <- bind_rows(
277
289
.data_group ,
278
- tibble(time_value = c(
279
- missing_times ,
280
- .date_seq_list $ pad_early_dates ,
281
- .date_seq_list $ pad_late_dates
282
- ), .real = FALSE )
290
+ dplyr :: bind_cols(
291
+ .group_key ,
292
+ tibble(
293
+ time_value = c(
294
+ missing_times ,
295
+ .date_seq_list $ pad_early_dates ,
296
+ .date_seq_list $ pad_late_dates
297
+ ), .real = FALSE
298
+ )
299
+ )
283
300
) %> %
284
301
arrange(.data $ time_value )
285
302
@@ -405,8 +422,8 @@ epi_slide_one_group <- function(
405
422
)),
406
423
capture.output(print(waldo :: compare(
407
424
res [[comp_nms [[comp_i ]]]], slide_values [[comp_i ]],
408
- x_arg = rlang :: expr_deparse(expr(`$`(existing , !! sym(comp_nms [[comp_i ]])))),
409
- y_arg = rlang :: expr_deparse(expr(`$`(comp_value , !! sym(comp_nms [[comp_i ]]))))
425
+ x_arg = rlang :: expr_deparse(dplyr :: expr(`$`(existing , !! sym(comp_nms [[comp_i ]])))), # nolint: object_usage_linter
426
+ y_arg = rlang :: expr_deparse(dplyr :: expr(`$`(comp_value , !! sym(comp_nms [[comp_i ]])))) # nolint: object_usage_linter
410
427
))),
411
428
cli :: format_message(c(
412
429
" >" = " You likely want to rename or remove this column from your slide
@@ -711,7 +728,7 @@ epi_slide_opt <- function(
711
728
# positions of user-provided `col_names` into string column names. We avoid
712
729
# using `names(pos)` directly for robustness and in case we later want to
713
730
# allow users to rename fields via tidyselection.
714
- if (class (quo_get_expr(enquo(.col_names ))) == " character" ) {
731
+ if (inherits (quo_get_expr(enquo(.col_names )), " character" ) ) {
715
732
pos <- eval_select(dplyr :: all_of(.col_names ), data = .x , allow_rename = FALSE )
716
733
} else {
717
734
pos <- eval_select(enquo(.col_names ), data = .x , allow_rename = FALSE )
0 commit comments