@@ -376,10 +376,21 @@ epix_merge = function(x, y,
376376# ' @param ... Additional arguments to pass to the function or formula specified
377377# ' via `f`. Alternatively, if `f` is missing, then the current argument is
378378# ' interpreted as an expression for tidy evaluation.
379- # ' @param n Number of time steps to use in the running window. For example, if
380- # ' `n = 7`, and one time step is one day, then to produce a value on January 7
381- # ' we apply the given function or formula to data in between January 1 and
382- # ' 7.
379+ # ' @param before How far `before` each `ref_time_value` should the sliding
380+ # ' window extend? If provided, should be a single, non-NA,
381+ # ' [integer-compatible][vctrs::vec_cast] number of time steps. This window
382+ # ' endpoint is inclusive. For example, if `before = 7`, and one time step is
383+ # ' one day, then to produce a value for a `ref_time_value` of January 8, we
384+ # ' apply the given function or formula to data (for each group present) with
385+ # ' `time_value`s from January 1 onward, as they were reported on January 8.
386+ # ' For typical disease surveillance sources, this will not include any data
387+ # ' with a `time_value` of January 8, and, depending on the amount of reporting
388+ # ' latency, may not include January 7 or even earlier `time_value`s. (If
389+ # ' instead the archive were to hold nowcasts instead of regular surveillance
390+ # ' data, then we would indeed expect data for `time_value` January 8. If it
391+ # ' were to hold forecasts, then we would expect data for `time_value`s after
392+ # ' January 8, and the sliding window would extend as far after each
393+ # ' `ref_time_value` as needed to include all such `time_value`s.)
383394# ' @param group_by The variable(s) to group by before slide computation. If
384395# ' missing, then the keys in the underlying data table, excluding `time_value`
385396# ' and `version`, will be used for grouping. To omit a grouping entirely, use
@@ -414,10 +425,14 @@ epix_merge = function(x, y,
414425# ' values.
415426# '
416427# ' @details Two key distinctions between inputs to the current function and
417- # ' `epi_slide()`:
418- # ' 1. `epix_slide()` uses windows that are **always right-aligned** (in
419- # ' `epi_slide()`, custom alignments could be specified using the `align` or
420- # ' `before` arguments).
428+ # ' [`epi_slide()`]:
429+ # ' 1. `epix_slide()` doesn't accept an `after` argument; its windows extend
430+ # ' from `before` time steps before a given `ref_time_value` through the last
431+ # ' `time_value` available as of version `ref_time_value` (typically, this
432+ # ' won't include `ref_time_value` itself, as observations about a particular
433+ # ' time interval (e.g., day) are only published after that time interval ends);
434+ # ' `epi_slide` windows extend from `before` time steps before a
435+ # ' `ref_time_value` through `after` time steps after `ref_time_value`.
421436# ' 2. `epix_slide()` uses a `group_by` to specify the grouping upfront (in
422437# ' `epi_slide()`, this would be accomplished by a preceding function call to
423438# ' `dplyr::group_by()`).
@@ -440,11 +455,11 @@ epix_merge = function(x, y,
440455# ' Finally, this is simply a wrapper around the `slide()` method of the
441456# ' `epi_archive` class, so if `x` is an `epi_archive` object, then:
442457# ' ```
443- # ' epix_slide(x, new_var = comp(old_var), n = 120 )
458+ # ' epix_slide(x, new_var = comp(old_var), before = 119 )
444459# ' ```
445460# ' is equivalent to:
446461# ' ```
447- # ' x$slide(x, new_var = comp(old_var), n = 120 )
462+ # ' x$slide(new_var = comp(old_var), before = 119 )
448463# ' ```
449464# '
450465# ' @importFrom rlang enquo
@@ -462,15 +477,15 @@ epix_merge = function(x, y,
462477# ' by = "1 day")
463478# ' epix_slide(x = archive_cases_dv_subset,
464479# ' f = ~ mean(.x$case_rate_7d_av),
465- # ' n = 3 ,
480+ # ' before = 2 ,
466481# ' group_by = geo_value,
467482# ' ref_time_values = time_values,
468483# ' new_col_name = 'case_rate_3d_av')
469- epix_slide = function (x , f , ... , n , group_by , ref_time_values ,
484+ epix_slide = function (x , f , ... , before , group_by , ref_time_values ,
470485 time_step , new_col_name = " slide_value" ,
471486 as_list_col = FALSE , names_sep = " _" , all_rows = FALSE ) {
472487 if (! inherits(x , " epi_archive" )) Abort(" `x` must be of class `epi_archive`." )
473- return (x $ slide(f , ... , n = n ,
488+ return (x $ slide(f , ... , before = before ,
474489 group_by = {{group_by }},
475490 ref_time_values = ref_time_values ,
476491 time_step = time_step ,
0 commit comments