Skip to content

Commit 30fd094

Browse files
committed
Merge remote-tracking branch 'upstream/dev' into 446-promote-other_keys
Resolve conflict regarding testing tz (US/Aleutian instead of alternative UTC or old buggy ET).
2 parents 35ec675 + 8dff011 commit 30fd094

21 files changed

+379
-68
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: epiprocess
33
Title: Tools for basic signal processing in epidemiology
4-
Version: 0.8.3
4+
Version: 0.8.4
55
Authors@R: c(
66
person("Jacob", "Bien", role = "ctb"),
77
person("Logan", "Brooks", , "[email protected]", role = c("aut", "cre")),

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
S3method("[",epi_df)
44
S3method("names<-",epi_df)
5+
S3method(arrange_canonical,default)
6+
S3method(arrange_canonical,epi_df)
57
S3method(as_epi_df,data.frame)
68
S3method(as_epi_df,epi_df)
79
S3method(as_epi_df,tbl_df)
@@ -45,6 +47,7 @@ S3method(unnest,epi_df)
4547
export("%>%")
4648
export(archive_cases_dv_subset)
4749
export(arrange)
50+
export(arrange_canonical)
4851
export(as_epi_archive)
4952
export(as_epi_df)
5053
export(as_tsibble)

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.x.y will indicat
1818
## Bug fixes
1919

2020
- Fix `epi_slide_opt` (and related functions) to correctly handle `before=Inf`.
21+
Also allow multiple columns specified as a list of strings.
2122
- Disallow `after=Inf` in slide functions, since it doesn't seem like a likely
2223
use case and complicates code.
2324

R/key_colnames.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ key_colnames.default <- function(x, ...) {
1818
#' @export
1919
key_colnames.data.frame <- function(x, other_keys = character(0L), ...) {
2020
assert_character(other_keys)
21-
nm <- c("time_value", "geo_value", other_keys)
21+
nm <- c("geo_value", "time_value", other_keys)
2222
intersect(nm, colnames(x))
2323
}
2424

2525
#' @export
2626
key_colnames.epi_df <- function(x, ...) {
2727
other_keys <- attr(x, "metadata")$other_keys
28-
c("time_value", "geo_value", other_keys)
28+
c("geo_value", "time_value", other_keys)
2929
}
3030

3131
#' @export
3232
key_colnames.epi_archive <- function(x, ...) {
3333
other_keys <- attr(x, "metadata")$other_keys
34-
c("time_value", "geo_value", other_keys)
34+
c("geo_value", "time_value", other_keys)
3535
}
3636

3737
kill_time_value <- function(v) {

R/methods-epi_archive.R

Lines changed: 68 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -240,16 +240,75 @@ epix_fill_through_version <- function(x, fill_versions_end,
240240
#' earliest version that could be clobbered in either input archive.
241241
#'
242242
#' @examples
243-
#' # create two example epi_archive datasets
244-
#' x <- archive_cases_dv_subset$DT %>%
245-
#' dplyr::select(geo_value, time_value, version, case_rate_7d_av) %>%
246-
#' as_epi_archive(compactify = TRUE)
247-
#' y <- archive_cases_dv_subset$DT %>%
248-
#' dplyr::select(geo_value, time_value, version, percent_cli) %>%
249-
#' as_epi_archive(compactify = TRUE)
250-
#' # merge results stored in a third object:
251-
#' xy <- epix_merge(x, y)
243+
#' # Example 1
244+
#' # The s1 signal at August 1st gets revised from 10 to 11 on August 2nd
245+
#' s1 <- tibble::tibble(
246+
#' geo_value = c("ca", "ca", "ca"),
247+
#' time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02")),
248+
#' version = as.Date(c("2024-08-01", "2024-08-02", "2024-08-02")),
249+
#' signal1 = c(10, 11, 7)
250+
#' )
251+
#'
252+
#' s2 <- tibble::tibble(
253+
#' geo_value = c("ca", "ca"),
254+
#' time_value = as.Date(c("2024-08-01", "2024-08-02")),
255+
#' version = as.Date(c("2024-08-03", "2024-08-03")),
256+
#' signal2 = c(2, 3)
257+
#' )
258+
#'
259+
#'
260+
#' s1 <- s1 %>% as_epi_archive()
261+
#' s2 <- s2 %>% as_epi_archive()
262+
#'
263+
#' merged <- epix_merge(s1, s2, sync = "locf")
264+
#' merged[["DT"]]
265+
#'
266+
#' # Example 2
267+
#' # The s1 signal at August 1st gets revised from 12 to 13 on August 3rd
268+
#' s1 <- tibble::tibble(
269+
#' geo_value = c("ca", "ca", "ca", "ca"),
270+
#' time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02", "2024-08-03")),
271+
#' version = as.Date(c("2024-08-01", "2024-08-03", "2024-08-03", "2024-08-03")),
272+
#' signal1 = c(12, 13, 22, 19)
273+
#' )
274+
#'
275+
#' s2 <- tibble::tibble(
276+
#' geo_value = c("ca", "ca"),
277+
#' time_value = as.Date(c("2024-08-01", "2024-08-02")),
278+
#' version = as.Date(c("2024-08-02", "2024-08-02")),
279+
#' signal2 = c(4, 5),
280+
#' )
281+
#'
282+
#'
283+
#' s1 <- s1 %>% as_epi_archive()
284+
#' s2 <- s2 %>% as_epi_archive()
285+
#'
286+
#' merged <- epix_merge(s1, s2, sync = "locf")
287+
#' merged[["DT"]]
288+
#'
289+
#'
290+
#' # Example 3:
291+
#' s1 <- tibble::tibble(
292+
#' geo_value = c("ca", "ca", "ca"),
293+
#' time_value = as.Date(c("2024-08-01", "2024-08-02", "2024-08-03")),
294+
#' version = as.Date(c("2024-08-01", "2024-08-02", "2024-08-03")),
295+
#' signal1 = c(14, 11, 9)
296+
#' )
297+
#'
298+
#' # The s2 signal at August 1st gets revised from 3 to 5 on August 3rd
299+
#' s2 <- tibble::tibble(
300+
#' geo_value = c("ca", "ca", "ca"),
301+
#' time_value = as.Date(c("2024-08-01", "2024-08-01", "2024-08-02")),
302+
#' version = as.Date(c("2024-08-02", "2024-08-03", "2024-08-03")),
303+
#' signal2 = c(3, 5, 2),
304+
#' )
305+
#'
306+
#' s1 <- s1 %>% as_epi_archive()
307+
#' s2 <- s2 %>% as_epi_archive()
252308
#'
309+
#' # Some LOCF for signal 1 as signal 2 gets updated
310+
#' merged <- epix_merge(s1, s2, sync = "locf")
311+
#' merged[["DT"]]
253312
#' @importFrom data.table key set setkeyv
254313
#' @export
255314
epix_merge <- function(x, y,

R/methods-epi_df.R

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,3 +347,36 @@ reclass <- function(x, metadata) {
347347
attributes(x)$metadata <- metadata
348348
return(x)
349349
}
350+
351+
#' Arrange an epi_df into a standard order
352+
#'
353+
#' Moves [key_colnames()] to the left, then arranges rows based on that
354+
#' ordering. This function is mainly for use in tests and so that
355+
#' other function output will be in predictable order, where necessary.
356+
#'
357+
#' @param x an `epi_df`. Other objects will produce a warning and return as is.
358+
#' @param ... not used
359+
#'
360+
#' @keywords internal
361+
#' @export
362+
arrange_canonical <- function(x, ...) {
363+
UseMethod("arrange_canonical")
364+
}
365+
366+
#' @export
367+
arrange_canonical.default <- function(x, ...) {
368+
rlang::check_dots_empty()
369+
cli::cli_abort(c(
370+
"`arrange_canonical()` is only meaningful for an {.cls epi_df}."
371+
))
372+
return(x)
373+
}
374+
375+
#' @export
376+
arrange_canonical.epi_df <- function(x, ...) {
377+
rlang::check_dots_empty()
378+
keys <- key_colnames(x)
379+
x %>%
380+
dplyr::relocate(dplyr::all_of(keys), .before = 1) %>%
381+
dplyr::arrange(dplyr::across(dplyr::all_of(keys)))
382+
}

R/slide.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
#'
4040
#' @importFrom lubridate days weeks
4141
#' @importFrom dplyr bind_rows group_vars filter select
42-
#' @importFrom rlang .data .env !! enquo enquos sym env missing_arg
42+
#' @importFrom rlang .data .env !! enquos sym env missing_arg
4343
#' @export
4444
#' @seealso [`epi_slide_opt`] [`epi_slide_mean`] [`epi_slide_sum`]
4545
#' @examples
@@ -327,7 +327,7 @@ epi_slide <- function(x, f, ..., before = NULL, after = NULL, ref_time_values =
327327
#'
328328
#' @template opt-slide-details
329329
#'
330-
#' @importFrom dplyr bind_rows mutate %>% arrange tibble select
330+
#' @importFrom dplyr bind_rows mutate %>% arrange tibble select all_of
331331
#' @importFrom rlang enquo quo_get_expr as_label expr_label caller_arg
332332
#' @importFrom tidyselect eval_select
333333
#' @importFrom purrr map map_lgl
@@ -509,7 +509,11 @@ epi_slide_opt <- function(x, col_names, f, ..., before = NULL, after = NULL, ref
509509
# positions of user-provided `col_names` into string column names. We avoid
510510
# using `names(pos)` directly for robustness and in case we later want to
511511
# allow users to rename fields via tidyselection.
512-
pos <- eval_select(rlang::enquo(col_names), data = x, allow_rename = FALSE)
512+
if (class(quo_get_expr(enquo(col_names))) == "character") {
513+
pos <- eval_select(all_of(col_names), data = x, allow_rename = FALSE)
514+
} else {
515+
pos <- eval_select(enquo(col_names), data = x, allow_rename = FALSE)
516+
}
513517
col_names_chr <- names(x)[pos]
514518
# Always rename results to "slide_value_<original column name>".
515519
result_col_names <- paste0("slide_value_", col_names_chr)

man-roxygen/opt-slide-params.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#' @param col_names <[`tidy-select`][dplyr_tidy_select]> An unquoted column
2-
#' name(e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`), or
3-
#' [other tidy-select expression][tidyselect::language]. Variable names can
4-
#' be used as if they were positions in the data frame, so expressions like
5-
#' `x:y` can be used to select a range of variables. If you have the desired
6-
#' column names stored in a vector `vars`, use `col_names = all_of(vars)`.
2+
#' name(e.g., `cases`), multiple column names (e.g., `c(cases, deaths)`),
3+
#' [other tidy-select expression][tidyselect::language], or a vector of
4+
#' characters (e.g. `c("cases", "deaths")`). Variable names can be used as if
5+
#' they were positions in the data frame, so expressions like `x:y` can be
6+
#' used to select a range of variables.
77
#'
88
#' The tidy-selection renaming interface is not supported, and cannot be used
99
#' to provide output column names; if you want to customize the output column

man/arrange_canonical.Rd

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

man/epi_slide_mean.Rd

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

0 commit comments

Comments
 (0)