Skip to content

Commit 78b1c51

Browse files
committed
WIP docs(epix_epi_slide_opt_one_epikey): initial
1 parent 9ece085 commit 78b1c51

File tree

2 files changed

+122
-0
lines changed

2 files changed

+122
-0
lines changed

R/epix_epi_slide_opt.R

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,51 @@
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
147
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
249
unit_step <- epiprocess:::unit_time_delta(time_type)
350
prev_inp_snapshot <- NULL
451
prev_out_snapshot <- NULL
@@ -148,6 +195,7 @@ epix_epi_slide_opt.epi_archive <-
148195
group_updates <- group_values %>%
149196
nest(.by = version, .key = "subtbl") %>%
150197
arrange(version)
198+
# TODO move nesting inside the helper?
151199
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) %>%
152200
list_rbind()
153201
if (use_progress) cli::cli_progress_update(id = progress_bar_id)

man/epix_epi_slide_opt_one_epikey.Rd

Lines changed: 74 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)