|
| 1 | +#' Core operation of `epix_epi_slide_opt` for a single epikey's history |
| 2 | +#' |
| 3 | +#' @param updates tibble with two columns: `version` and `subtbl`; `subtbl` is a |
| 4 | +#' list of tibbles, each with a `time_value` column and measurement columns. |
| 5 | +#' The epikey should not appear. |
| 6 | +#' @param in_colnames chr; names of columns to which to apply `f_dots_baked` |
| 7 | +#' @param f_dots_baked supported sliding function from `{data.table}` or |
| 8 | +#' `{slider}`, potentially with some arguments baked in with |
| 9 | +#' [`purrr::partial`] |
| 10 | +#' @param f_from_package string; name of package from which `f_dots_baked` |
| 11 | +#' (pre-`partial`) originates |
| 12 | +#' @param before integerish >=0 or Inf; number of time steps before each |
| 13 | +#' ref_time_value to include in the sliding window computation; Inf to include |
| 14 | +#' all times beginning with the min `time_value` |
| 15 | +#' @param after integerish >=0; number of time steps after each ref_time_value |
| 16 | +#' to include in the sliding window computation |
| 17 | +#' @param time_type as in `new_epi_archive` |
| 18 | +#' @param out_colnames chr, same length as `in_colnames`; column names to use |
| 19 | +#' for results |
| 20 | +#' @return list of tibbles with same names as `subtbl`s plus: `c(out_colnames, |
| 21 | +#' "version")`; (compactified) diff data to put into an `epi_archive` |
| 22 | +#' |
| 23 | +#' @examples |
| 24 | +#' |
| 25 | +#' library(dplyr) |
| 26 | +#' updates <- bind_rows( |
| 27 | +#' tibble( |
| 28 | +#' version = 40, time_value = 1:10, value = 1:10 |
| 29 | +#' ), |
| 30 | +#' tibble( |
| 31 | +#' version = 12, time_value = 2:3, value = 3:2 |
| 32 | +#' ), |
| 33 | +#' tibble( |
| 34 | +#' version = 13, time_value = 6, value = 7, |
| 35 | +#' ), |
| 36 | +#' tibble( |
| 37 | +#' version = 13, time_value = 7, value = NA, |
| 38 | +#' ) |
| 39 | +#' ) %>% |
| 40 | +#' mutate(across(c(version, time_value), ~ as.Date("2020-01-01") - 1 + .x)) %>% |
| 41 | +#' tidyr::nest(.by = version, .key = "subtbl") |
| 42 | +#' |
| 43 | +#' updates %>% |
| 44 | +#' epix_epi_slide_opt_one_epikey("value", data.table::frollmean, "data.table", 1L, 0L, "day", "slide_value") |
| 45 | +#' |
| 46 | +#' @keywords internal |
1 | 47 | epix_epi_slide_opt_one_epikey <- function(updates, in_colnames, f_dots_baked, f_from_package, before, after, time_type, out_colnames) { |
| 48 | + # TODO check for col name clobbering |
2 | 49 | unit_step <- epiprocess:::unit_time_delta(time_type) |
3 | 50 | prev_inp_snapshot <- NULL |
4 | 51 | prev_out_snapshot <- NULL |
@@ -148,6 +195,7 @@ epix_epi_slide_opt.epi_archive <- |
148 | 195 | group_updates <- group_values %>% |
149 | 196 | nest(.by = version, .key = "subtbl") %>% |
150 | 197 | arrange(version) |
| 198 | + # TODO move nesting inside the helper? |
151 | 199 | res <- epix_epi_slide_opt_one_epikey(group_updates, names_info$input_col_names, .f_dots_baked, .f_info$from_package, window_args$before, window_args$after, time_type, names_info$output_col_names) %>% |
152 | 200 | list_rbind() |
153 | 201 | if (use_progress) cli::cli_progress_update(id = progress_bar_id) |
|
0 commit comments