@@ -537,7 +537,7 @@ get_before_after_from_window <- function(window_size, align, time_type) {
537
537
# '
538
538
# ' @template basic-slide-params
539
539
# ' @param .col_names <[`tidy-select`][dplyr_tidy_select]> An unquoted column
540
- # ' name(e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`),
540
+ # ' name (e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`),
541
541
# ' [other tidy-select expression][tidyselect::language], or a vector of
542
542
# ' characters (e.g. `c("cases", "deaths")`). Variable names can be used as if
543
543
# ' they were positions in the data frame, so expressions like `x:y` can be
@@ -692,6 +692,36 @@ epi_slide_opt <- function(
692
692
}
693
693
f_from_package <- f_info $ package
694
694
695
+ user_provided_rtvs <- ! is.null(.ref_time_values )
696
+ if (! user_provided_rtvs ) {
697
+ .ref_time_values <- unique(.x $ time_value )
698
+ } else {
699
+ assert_numeric(.ref_time_values , min.len = 1L , null.ok = FALSE , any.missing = FALSE )
700
+ if (! test_subset(.ref_time_values , unique(.x $ time_value ))) {
701
+ cli_abort(
702
+ " `ref_time_values` must be a unique subset of the time values in `x`." ,
703
+ class = " epiprocess__epi_slide_opt_invalid_ref_time_values"
704
+ )
705
+ }
706
+ if (anyDuplicated(.ref_time_values ) != 0L ) {
707
+ cli_abort(
708
+ " `ref_time_values` must not contain any duplicates; use `unique` if appropriate." ,
709
+ class = " epiprocess__epi_slide_opt_invalid_ref_time_values"
710
+ )
711
+ }
712
+ }
713
+ ref_time_values <- sort(.ref_time_values )
714
+
715
+ # Handle window arguments
716
+ .align <- rlang :: arg_match(.align )
717
+ time_type <- attr(.x , " metadata" )$ time_type
718
+ if (is.null(.window_size )) {
719
+ cli_abort(" epi_slide_opt: `.window_size` must be specified." )
720
+ }
721
+ validate_slide_window_arg(.window_size , time_type )
722
+ window_args <- get_before_after_from_window(.window_size , .align , time_type )
723
+
724
+ # Handle output naming
695
725
assert_string(.prefix , null.ok = TRUE )
696
726
assert_string(.suffix , null.ok = TRUE )
697
727
assert_character(.new_col_names , len = length(col_names_chr ), null.ok = TRUE )
@@ -701,21 +731,22 @@ epi_slide_opt <- function(
701
731
)
702
732
}
703
733
if (is.null(.prefix ) && is.null(.suffix ) && is.null(.new_col_names )) {
704
- .suffix <- " _{.window_size }{.time_unit}{.f_abbr}"
734
+ .suffix <- " _{.n }{.time_unit}{.f_abbr}"
705
735
}
706
736
if (! is.null(.prefix ) || ! is.null(.suffix )) {
707
737
.prefix <- .prefix %|| % " "
708
738
.suffix <- .suffix %|| % " "
739
+ # FIXME alignment marker
709
740
glue_env <- rlang :: env(
710
- .window_size = .window_size , # FIXME typing
711
- .time_unit = " d " , # FIXME
741
+ .n = time_delta_to_n_steps( .window_size , time_type ), # FIXME Inf...
742
+ .time_unit = time_type_unit_abbr( time_type ),
712
743
.f_abbr = f_info $ abbr ,
713
744
quo_get_env(col_names_quo )
714
745
)
715
746
.new_col_names <- unclass(
716
747
glue(.prefix , .envir = glue_env ) +
717
- col_names_chr +
718
- glue(.suffix , .envir = glue_env )
748
+ col_names_chr +
749
+ glue(.suffix , .envir = glue_env )
719
750
)
720
751
} else {
721
752
# `.new_col_names` was provided by user; we don't need to do anything.
@@ -728,35 +759,6 @@ epi_slide_opt <- function(
728
759
}
729
760
result_col_names <- .new_col_names
730
761
731
- user_provided_rtvs <- ! is.null(.ref_time_values )
732
- if (! user_provided_rtvs ) {
733
- .ref_time_values <- unique(.x $ time_value )
734
- } else {
735
- assert_numeric(.ref_time_values , min.len = 1L , null.ok = FALSE , any.missing = FALSE )
736
- if (! test_subset(.ref_time_values , unique(.x $ time_value ))) {
737
- cli_abort(
738
- " `ref_time_values` must be a unique subset of the time values in `x`." ,
739
- class = " epiprocess__epi_slide_opt_invalid_ref_time_values"
740
- )
741
- }
742
- if (anyDuplicated(.ref_time_values ) != 0L ) {
743
- cli_abort(
744
- " `ref_time_values` must not contain any duplicates; use `unique` if appropriate." ,
745
- class = " epiprocess__epi_slide_opt_invalid_ref_time_values"
746
- )
747
- }
748
- }
749
- ref_time_values <- sort(.ref_time_values )
750
-
751
- # Handle window arguments
752
- .align <- rlang :: arg_match(.align )
753
- time_type <- attr(.x , " metadata" )$ time_type
754
- if (is.null(.window_size )) {
755
- cli_abort(" epi_slide_opt: `.window_size` must be specified." )
756
- }
757
- validate_slide_window_arg(.window_size , time_type )
758
- window_args <- get_before_after_from_window(.window_size , .align , time_type )
759
-
760
762
# Make a complete date sequence between min(.x$time_value) and max(.x$time_value).
761
763
date_seq_list <- full_date_seq(.x , window_args $ before , window_args $ after , time_type )
762
764
all_dates <- date_seq_list $ all_dates
0 commit comments