Skip to content

Commit 0148bdc

Browse files
committed
Merge branch 'main' of https://github.com/cmu-delphi/epiprocess into km-test-methods-epi_archive
2 parents fcadb26 + cce84ad commit 0148bdc

File tree

7 files changed

+24
-58
lines changed

7 files changed

+24
-58
lines changed

.Rbuildignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@
88
^data-raw$
99
^_pkgdown\.yml$
1010
^pkgdown$
11+
^doc$
12+
^Meta$

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
*.Rproj
66
inst/doc
77
docs
8+
/doc/
9+
/Meta/
10+
*.DS_Store

R/methods-epi_df.R

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,14 @@ summary.epi_df = function(object, ...) {
9999

100100
cn <- names(res)
101101
nr <- vctrs::vec_size(x)
102-
not_epi_df <- (!("time_value" %in% cn) || !("geo_value" %in% cn)
103-
|| vctrs::vec_size(res) > nr || any(i > nr))
102+
not_epi_df <- (!("time_value" %in% cn) || !("geo_value" %in% cn) || vctrs::vec_size(res) > nr || any(i > nr))
104103

105104
if (not_epi_df) return(tibble::as_tibble(res))
106105

107106
# Case when i is numeric and there are duplicate values in it
108107
if (is.numeric(i) && vctrs::vec_duplicate_any(i) > 0)
109108
return(tibble::as_tibble(res))
110109

111-
# Column subsetting only, then return res as tibble
112-
if (rlang::is_null(i) && !rlang::is_null(j))
113-
return(tibble::as_tibble(res))
114-
115110
att_x = attr(x, "metadata")
116111
new_epi_df(tibble::as_tibble(res),
117112
geo_type = att_x$geo_type,

R/slide.R

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@
88
#' @param f Function or formula to slide over variables in `x`. To "slide" means
99
#' to apply a function or formula over a running window of `n` time steps
1010
#' (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.
1619
#' @param ... Additional arguments to pass to the function or formula specified
1720
#' via `f`. Alternatively, if `f` is missing, then the current argument is
1821
#' interpreted as an expression for tidy evaluation. See details.
@@ -85,26 +88,6 @@
8588
#' inferred from the given expression and overrides any name passed explicitly
8689
#' through the `new_col_name` argument.
8790
#'
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-
#'
10891
#' @importFrom lubridate days weeks
10992
#' @importFrom rlang .data .env !! enquo enquos sym
11093
#' @export

man/epi_slide.Rd

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

tests/testthat/test-epi_slide.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ test_that("`ref_time_values` + `align` that have some slide data, but generate t
2727
test_that("these doesn't produce an error; the error appears only if the ref time values are out of the range for every group", {
2828
expect_identical(edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-01")+200L) %>%
2929
dplyr::select("geo_value","slide_value_value"),
30-
dplyr::tibble(geo_value = "ak", slide_value_value = 199) %>% group_by(geo_value)) # out of range for one group
30+
dplyr::tibble(geo_value = "ak", slide_value_value = 199)) # out of range for one group
3131
expect_identical(edf %>% group_by(geo_value) %>% epi_slide(f, n=3L, ref_time_values=as.Date("2020-01-04")) %>%
3232
dplyr::select("geo_value","slide_value_value"),
33-
dplyr::tibble(geo_value = c("ak", "al"), slide_value_value = c(2, -2)) %>% group_by(geo_value)) # not out of range for either group
33+
dplyr::tibble(geo_value = c("ak", "al"), slide_value_value = c(2, -2))) # not out of range for either group
3434
})
8 KB
Binary file not shown.

0 commit comments

Comments
 (0)