@@ -587,7 +587,8 @@ get_before_after_from_window <- function(window_size, align, time_type) {
587587# ' `time_type` of `.x`
588588# ' - `{.align_abbr}` will be `""` if `.align` is the default of `"right"`;
589589# ' otherwise, it will be the first letter of `.align`
590- # ' - `{.f_abbr}` will be a short string based on what `.f`
590+ # ' - `{.f_abbr}` will be a character vector containing a short abbreviation
591+ # ' for `.f` factoring in the input column type(s) for `.col_names`
591592# '
592593# ' @importFrom dplyr bind_rows mutate %>% arrange tibble select all_of
593594# ' @importFrom rlang enquo expr_label caller_arg quo_get_env
@@ -681,22 +682,24 @@ epi_slide_opt <- function(
681682 col_names_chr <- names(.x )[pos ]
682683
683684 # Check that slide function `.f` is one of those short-listed from
684- # `data.table` and `slider` (or a function that has the exact same
685- # definition, e.g. if the function has been reexported or defined
686- # locally).
685+ # `data.table` and `slider` (or a function that has the exact same definition,
686+ # e.g. if the function has been reexported or defined locally). Extract some
687+ # metadata. `namer` will be mapped over columns (.x will be a column, not the
688+ # entire edf).
689+ tautology <- function (col ) TRUE
687690 f_possibilities <-
688691 tibble :: tribble(
689- ~ f , ~ package , ~ abbr ,
690- frollmean , " data.table" , " av" ,
691- frollsum , " data.table" , " sum" ,
692- frollapply , " data.table" , " slide" ,
693- slide_sum , " slider" , " sum" ,
694- slide_prod , " slider" , " prod" ,
695- slide_mean , " slider" , " av" ,
696- slide_min , " slider" , " min" ,
697- slide_max , " slider" , " max" ,
698- slide_all , " slider" , " all" ,
699- slide_any , " slider" , " any" ,
692+ ~ f , ~ package , ~ namer ,
693+ frollmean , " data.table" , ~ if (is.logical( .x )) " prop " else " av" ,
694+ frollsum , " data.table" , ~ if (is.logical( .x )) " count " else " sum" ,
695+ frollapply , " data.table" , ~ " slide" ,
696+ slide_sum , " slider" , ~ if (is.logical( .x )) " count " else " sum" ,
697+ slide_prod , " slider" , ~ " prod" ,
698+ slide_mean , " slider" , ~ if (is.logical( .x )) " prop " else " av" ,
699+ slide_min , " slider" , ~ " min" ,
700+ slide_max , " slider" , ~ " max" ,
701+ slide_all , " slider" , ~ " all" ,
702+ slide_any , " slider" , ~ " any" ,
700703 )
701704 f_info <- f_possibilities %> %
702705 filter(map_lgl(.data $ f , ~ identical(.f , .x )))
@@ -780,7 +783,7 @@ epi_slide_opt <- function(
780783 .n = n ,
781784 .time_unit_abbr = time_unit_abbr ,
782785 .align_abbr = align_abbr ,
783- .f_abbr = f_info $ abbr ,
786+ .f_abbr = purrr :: map_chr( .x [ col_names_chr ], unwrap( f_info $ namer )) ,
784787 quo_get_env(col_names_quo )
785788 )
786789 .new_col_names <- unclass(
0 commit comments