|
8 | 8 | #' @param f Function or formula to slide over variables in `x`. To "slide" means |
9 | 9 | #' to apply a function or formula over a running window of `n` time steps |
10 | 10 | #' (where one time step is typically one day or one week; see details for more |
11 | | -#' explanation). If a function, `f` must take `x`, a data frame with the same |
12 | | -#' column names as the original object; followed by any number of named |
13 | | -#' arguments; and ending with `...`. If a formula, `f` can operate directly on |
14 | | -#' columns accessed via `.x$var`, as in `~ mean(.x$var)` to compute a mean of |
15 | | -#' a column `var` over a sliding window of `n` time steps. |
| 11 | +#' explanation). If a function, `f` should take `x`, an `epi_df` with the same |
| 12 | +#' names as the non-grouping columns, followed by `g` to refer to the one row |
| 13 | +#' tibble with one column per grouping variable that identifies the group, |
| 14 | +#' and any number of named arguments (which will be taken from `...`). If a |
| 15 | +#' formula, `f` can operate directly on columns accessed via `.x$var`, as |
| 16 | +#' in `~ mean(.x$var)` to compute a mean of a column var over a sliding |
| 17 | +#' window of n time steps. As well, `.y` may be used in the formula to refer |
| 18 | +#' to the groupings that would be described by `g` if `f` was a function. |
16 | 19 | #' @param ... Additional arguments to pass to the function or formula specified |
17 | 20 | #' via `f`. Alternatively, if `f` is missing, then the current argument is |
18 | 21 | #' interpreted as an expression for tidy evaluation. See details. |
|
85 | 88 | #' inferred from the given expression and overrides any name passed explicitly |
86 | 89 | #' through the `new_col_name` argument. |
87 | 90 | #' |
88 | | -#' When `f` is a named function with arguments, if a tibble with an unnamed |
89 | | -#' grouping variable is passed in as the method argument to `f`, include a |
90 | | -#' parameter for the grouping-variable in `function()` just prior to |
91 | | -#' specifying the method to prevent that from being overridden. For example: |
92 | | -#' ``` |
93 | | -#' # Construct an tibble with an unnamed grouping variable |
94 | | -#' edf = bind_rows(tibble(geo_value = "ak", time_value = as.Date("2020-01-01") |
95 | | -#' + 1:10, x1=1:10, y=1:10 + rnorm(10L))) %>% |
96 | | -#' as_epi_df() |
97 | | -#' |
98 | | -#' # Now, include a row parameter for the grouping variable in the tibble, |
99 | | -#' # which we denote as g, just prior to method = "qr" |
100 | | -#' # Note that if g was not included below, then the method = "qr" would be |
101 | | -#' # overridden, as described above |
102 | | -#' edf %>% |
103 | | -#' group_by(geo_value) %>% |
104 | | -#' epi_slide(function(x, g, method="qr", ...) tibble(model=list( |
105 | | -#' lm(y ~ x1, x, method=method))), n=7L) |
106 | | -#' ``` |
107 | | -#' |
108 | 91 | #' @importFrom lubridate days weeks |
109 | 92 | #' @importFrom rlang .data .env !! enquo enquos sym |
110 | 93 | #' @export |
|
0 commit comments