diff --git a/NAMESPACE b/NAMESPACE index 51c4091c..3eeb6b0f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -49,6 +49,7 @@ S3method(ungroup,grouped_epi_archive2) S3method(unnest,epi_df) export("%>%") export(archive_cases_dv_subset) +export(archive_cases_dv_subset_2) export(arrange) export(as_epi_archive) export(as_epi_archive2) diff --git a/R/archive_new.R b/R/archive_new.R index bcfa84c3..0b4f3695 100644 --- a/R/archive_new.R +++ b/R/archive_new.R @@ -197,7 +197,7 @@ next_after.Date <- function(x) x + 1L #' value = rnorm(10, mean = 2, sd = 1) #' ) #' -#' toy_epi_archive <- tib %>% epi_archive$new( +#' toy_epi_archive <- tib %>% new_epi_archive2( #' geo_type = "state", #' time_type = "day" #' ) @@ -743,16 +743,16 @@ merge_epi_archive2 <- function( #' #' @examples #' -#' grouped_archive <- archive_cases_dv_subset %>% group_by(geo_value) +#' grouped_archive <- archive_cases_dv_subset_2 %>% group_by(geo_value) #' #' # `print` for metadata and method listing: #' grouped_archive %>% print() #' #' # The primary use for grouping is to perform a grouped `epix_slide`: #' -#' archive_cases_dv_subset %>% +#' archive_cases_dv_subset_2 %>% #' group_by(geo_value) %>% -#' epix_slide( +#' epix_slide2( #' f = ~ mean(.x$case_rate_7d_av), #' before = 2, #' ref_time_values = as.Date("2020-06-11") + 0:2, @@ -778,7 +778,7 @@ merge_epi_archive2 <- function( #' time_value = as.Date(time_value), #' version = as.Date(version) #' ) %>% -#' as_epi_archive(other_keys = "age_group") +#' as_epi_archive2(other_keys = "age_group") #' #' # The following are equivalent: #' toy_archive %>% group_by(geo_value, age_group) @@ -801,7 +801,7 @@ merge_epi_archive2 <- function( #' #' toy_archive %>% #' group_by(geo_value, age_group, .drop = FALSE) %>% -#' epix_slide(f = ~ sum(.x$value), before = 20) %>% +#' epix_slide2(f = ~ sum(.x$value), before = 20) %>% #' ungroup() #' #' @importFrom dplyr group_by @@ -1030,7 +1030,7 @@ slide.epi_archive2 <- function(epi_archive, f, ..., before, ref_time_values, #' value = rnorm(10, mean = 2, sd = 1) #' ) #' -#' toy_epi_archive <- tib %>% as_epi_archive( +#' toy_epi_archive <- tib %>% as_epi_archive2( #' geo_type = "state", #' time_type = "day" #' ) @@ -1056,7 +1056,7 @@ slide.epi_archive2 <- function(epi_archive, f, ..., before, ref_time_values, #' cases_rate = c(0.01, 0.02, 0.01, 0.05) #' ) #' -#' x <- df %>% as_epi_archive( +#' x <- df %>% as_epi_archive2( #' geo_type = "state", #' time_type = "day", #' other_keys = "county" @@ -1081,15 +1081,15 @@ as_epi_archive2 <- function(x, geo_type, time_type, other_keys, #' #' @export #' @examples -#' is_epi_archive(jhu_csse_daily_subset) # FALSE (this is an epi_df, not epi_archive) -#' is_epi_archive(archive_cases_dv_subset) # TRUE +#' is_epi_archive2(jhu_csse_daily_subset) # FALSE (this is an epi_df, not epi_archive) +#' is_epi_archive2(archive_cases_dv_subset_2) # TRUE #' #' # By default, grouped_epi_archives don't count as epi_archives, as they may #' # support a different set of operations from regular `epi_archives`. This #' # behavior can be controlled by `grouped_okay`. -#' grouped_archive <- archive_cases_dv_subset$group_by(geo_value) -#' is_epi_archive(grouped_archive) # FALSE -#' is_epi_archive(grouped_archive, grouped_okay = TRUE) # TRUE +#' grouped_archive <- archive_cases_dv_subset_2 %>% group_by(geo_value) +#' is_epi_archive2(grouped_archive) # FALSE +#' is_epi_archive2(grouped_archive, grouped_okay = TRUE) # TRUE #' #' @seealso [`is_grouped_epi_archive`] is_epi_archive2 <- function(x, grouped_okay = FALSE) { diff --git a/R/data.R b/R/data.R index 26b9f39f..37ccc522 100644 --- a/R/data.R +++ b/R/data.R @@ -289,3 +289,11 @@ delayed_assign_with_unregister_awareness( #' * Furthermore, the data has been limited to a very small number of rows, the #' signal names slightly altered, and formatted into a tibble. "jhu_csse_county_level_subset" + +#' @export +"archive_cases_dv_subset_2" + +delayed_assign_with_unregister_awareness( + "archive_cases_dv_subset_2", + as_epi_archive2(archive_cases_dv_subset_dt, compactify = FALSE) +) diff --git a/R/methods-epi_archive_new.R b/R/methods-epi_archive_new.R index 2bbdcd46..3ce39afc 100644 --- a/R/methods-epi_archive_new.R +++ b/R/methods-epi_archive_new.R @@ -41,17 +41,15 @@ #' #' @examples #' # warning message of data latency shown -#' epix_as_of( -#' x = archive_cases_dv_subset, -#' max_version = max(archive_cases_dv_subset$DT$version) +#' epix_as_of2( +#' archive_cases_dv_subset_2, +#' max_version = max(archive_cases_dv_subset_2$DT$version) #' ) #' -#' @examples -#' -#' range(archive_cases_dv_subset$DT$version) # 2020-06-02 -- 2021-12-01 +#' range(archive_cases_dv_subset_2$DT$version) # 2020-06-02 -- 2021-12-01 #' -#' epix_as_of( -#' x = archive_cases_dv_subset, +#' epix_as_of2( +#' archive_cases_dv_subset_2, #' max_version = as.Date("2020-06-12") #' ) #' @@ -65,9 +63,9 @@ #' # muffle such warnings with the following pattern: #' withCallingHandlers( #' { -#' epix_as_of( -#' x = archive_cases_dv_subset, -#' max_version = max(archive_cases_dv_subset$DT$version) +#' epix_as_of2( +#' archive_cases_dv_subset_2, +#' max_version = max(archive_cases_dv_subset_2$DT$version) #' ) #' }, #' epiprocess__snapshot_as_of_clobberable_version = function(wrn) invokeRestart("muffleWarning") @@ -164,16 +162,14 @@ epix_fill_through_version2 <- function(epi_archive, fill_versions_end, #' #' @examples #' # create two example epi_archive datasets -#' x <- archive_cases_dv_subset$DT %>% +#' x <- archive_cases_dv_subset_2$DT %>% #' dplyr::select(geo_value, time_value, version, case_rate_7d_av) %>% -#' as_epi_archive(compactify = TRUE) -#' y <- archive_cases_dv_subset$DT %>% +#' as_epi_archive2(compactify = TRUE) +#' y <- archive_cases_dv_subset_2$DT %>% #' dplyr::select(geo_value, time_value, version, percent_cli) %>% -#' as_epi_archive(compactify = TRUE) +#' as_epi_archive2(compactify = TRUE) #' # merge results stored in a third object: -#' xy <- epix_merge(x, y) -#' # vs. mutating x to hold the merge result: -#' x$merge(y) +#' xy <- epix_merge2(x, y) #' #' @importFrom data.table key set setkeyv #' @export @@ -703,9 +699,9 @@ epix_detailed_restricted_mutate2 <- function(.data, ...) { #' #' # A simple (but not very useful) example (see the archive vignette for a more #' # realistic one): -#' archive_cases_dv_subset %>% +#' archive_cases_dv_subset_2 %>% #' group_by(geo_value) %>% -#' epix_slide( +#' epix_slide2( #' f = ~ mean(.x$case_rate_7d_av), #' before = 2, #' ref_time_values = ref_time_values, @@ -727,9 +723,9 @@ epix_detailed_restricted_mutate2 <- function(.data, ...) { #' #' # Examining characteristics of the data passed to each computation with #' # `all_versions=FALSE`. -#' archive_cases_dv_subset %>% +#' archive_cases_dv_subset_2 %>% #' group_by(geo_value) %>% -#' epix_slide( +#' epix_slide2( #' function(x, gk, rtv) { #' tibble( #' time_range = if (nrow(x) == 0L) { @@ -756,9 +752,9 @@ epix_detailed_restricted_mutate2 <- function(.data, ...) { #' # to each computation. In this case, each computation should expect an #' # `epi_archive` containing the relevant version data: #' -#' archive_cases_dv_subset %>% +#' archive_cases_dv_subset_2 %>% #' group_by(geo_value) %>% -#' epix_slide( +#' epix_slide2( #' function(x, gk, rtv) { #' tibble( #' versions_start = if (nrow(x$DT) == 0L) { diff --git a/R/sysdata.rda b/R/sysdata.rda index d100711d..a2c5abfd 100644 Binary files a/R/sysdata.rda and b/R/sysdata.rda differ diff --git a/man/as_epi_archive2.Rd b/man/as_epi_archive2.Rd index 090b455a..bc3f5185 100644 --- a/man/as_epi_archive2.Rd +++ b/man/as_epi_archive2.Rd @@ -108,7 +108,7 @@ tib <- tibble::tibble( value = rnorm(10, mean = 2, sd = 1) ) -toy_epi_archive <- tib \%>\% as_epi_archive( +toy_epi_archive <- tib \%>\% as_epi_archive2( geo_type = "state", time_type = "day" ) @@ -134,7 +134,7 @@ df <- data.frame( cases_rate = c(0.01, 0.02, 0.01, 0.05) ) -x <- df \%>\% as_epi_archive( +x <- df \%>\% as_epi_archive2( geo_type = "state", time_type = "day", other_keys = "county" diff --git a/man/epi_archive.Rd b/man/epi_archive.Rd index efe5d5ba..86e21b89 100644 --- a/man/epi_archive.Rd +++ b/man/epi_archive.Rd @@ -213,7 +213,7 @@ tib <- tibble::tibble( value = rnorm(10, mean = 2, sd = 1) ) -toy_epi_archive <- tib \%>\% epi_archive$new( +toy_epi_archive <- tib \%>\% new_epi_archive2( geo_type = "state", time_type = "day" ) diff --git a/man/epix_as_of2.Rd b/man/epix_as_of2.Rd index 4bfe32f4..ac69e9a9 100644 --- a/man/epix_as_of2.Rd +++ b/man/epix_as_of2.Rd @@ -60,16 +60,15 @@ in the future. } \examples{ # warning message of data latency shown -epix_as_of( - x = archive_cases_dv_subset, - max_version = max(archive_cases_dv_subset$DT$version) +epix_as_of2( + archive_cases_dv_subset_2, + max_version = max(archive_cases_dv_subset_2$DT$version) ) +range(archive_cases_dv_subset_2$DT$version) # 2020-06-02 -- 2021-12-01 -range(archive_cases_dv_subset$DT$version) # 2020-06-02 -- 2021-12-01 - -epix_as_of( - x = archive_cases_dv_subset, +epix_as_of2( + archive_cases_dv_subset_2, max_version = as.Date("2020-06-12") ) @@ -83,9 +82,9 @@ epix_as_of( # muffle such warnings with the following pattern: withCallingHandlers( { - epix_as_of( - x = archive_cases_dv_subset, - max_version = max(archive_cases_dv_subset$DT$version) + epix_as_of2( + archive_cases_dv_subset_2, + max_version = max(archive_cases_dv_subset_2$DT$version) ) }, epiprocess__snapshot_as_of_clobberable_version = function(wrn) invokeRestart("muffleWarning") diff --git a/man/epix_merge2.Rd b/man/epix_merge2.Rd index a42e53e4..11d0aff5 100644 --- a/man/epix_merge2.Rd +++ b/man/epix_merge2.Rd @@ -59,15 +59,13 @@ be clobbered in either input archive. } \examples{ # create two example epi_archive datasets -x <- archive_cases_dv_subset$DT \%>\% +x <- archive_cases_dv_subset_2$DT \%>\% dplyr::select(geo_value, time_value, version, case_rate_7d_av) \%>\% - as_epi_archive(compactify = TRUE) -y <- archive_cases_dv_subset$DT \%>\% + as_epi_archive2(compactify = TRUE) +y <- archive_cases_dv_subset_2$DT \%>\% dplyr::select(geo_value, time_value, version, percent_cli) \%>\% - as_epi_archive(compactify = TRUE) + as_epi_archive2(compactify = TRUE) # merge results stored in a third object: -xy <- epix_merge(x, y) -# vs. mutating x to hold the merge result: -x$merge(y) +xy <- epix_merge2(x, y) } diff --git a/man/epix_slide2.Rd b/man/epix_slide2.Rd index 71d3a11c..8d822bc0 100644 --- a/man/epix_slide2.Rd +++ b/man/epix_slide2.Rd @@ -199,9 +199,9 @@ ref_time_values <- seq(as.Date("2020-06-01"), # A simple (but not very useful) example (see the archive vignette for a more # realistic one): -archive_cases_dv_subset \%>\% +archive_cases_dv_subset_2 \%>\% group_by(geo_value) \%>\% - epix_slide( + epix_slide2( f = ~ mean(.x$case_rate_7d_av), before = 2, ref_time_values = ref_time_values, @@ -223,9 +223,9 @@ archive_cases_dv_subset \%>\% # Examining characteristics of the data passed to each computation with # `all_versions=FALSE`. -archive_cases_dv_subset \%>\% +archive_cases_dv_subset_2 \%>\% group_by(geo_value) \%>\% - epix_slide( + epix_slide2( function(x, gk, rtv) { tibble( time_range = if (nrow(x) == 0L) { @@ -252,9 +252,9 @@ archive_cases_dv_subset \%>\% # to each computation. In this case, each computation should expect an # `epi_archive` containing the relevant version data: -archive_cases_dv_subset \%>\% +archive_cases_dv_subset_2 \%>\% group_by(geo_value) \%>\% - epix_slide( + epix_slide2( function(x, gk, rtv) { tibble( versions_start = if (nrow(x$DT) == 0L) { diff --git a/man/group_by.epi_archive2.Rd b/man/group_by.epi_archive2.Rd index 3191b134..fa9040c3 100644 --- a/man/group_by.epi_archive2.Rd +++ b/man/group_by.epi_archive2.Rd @@ -83,16 +83,16 @@ to \code{group_by_drop_default.default} (but there is a dedicated method for } \examples{ -grouped_archive <- archive_cases_dv_subset \%>\% group_by(geo_value) +grouped_archive <- archive_cases_dv_subset_2 \%>\% group_by(geo_value) # `print` for metadata and method listing: grouped_archive \%>\% print() # The primary use for grouping is to perform a grouped `epix_slide`: -archive_cases_dv_subset \%>\% +archive_cases_dv_subset_2 \%>\% group_by(geo_value) \%>\% - epix_slide( + epix_slide2( f = ~ mean(.x$case_rate_7d_av), before = 2, ref_time_values = as.Date("2020-06-11") + 0:2, @@ -118,7 +118,7 @@ toy_archive <- time_value = as.Date(time_value), version = as.Date(version) ) \%>\% - as_epi_archive(other_keys = "age_group") + as_epi_archive2(other_keys = "age_group") # The following are equivalent: toy_archive \%>\% group_by(geo_value, age_group) @@ -141,7 +141,7 @@ toy_archive \%>\% toy_archive \%>\% group_by(geo_value, age_group, .drop = FALSE) \%>\% - epix_slide(f = ~ sum(.x$value), before = 20) \%>\% + epix_slide2(f = ~ sum(.x$value), before = 20) \%>\% ungroup() } diff --git a/man/is_epi_archive2.Rd b/man/is_epi_archive2.Rd index fd2f0a1f..df258d3e 100644 --- a/man/is_epi_archive2.Rd +++ b/man/is_epi_archive2.Rd @@ -19,15 +19,15 @@ count? Default is \code{FALSE}.} Test for \code{epi_archive} format } \examples{ -is_epi_archive(jhu_csse_daily_subset) # FALSE (this is an epi_df, not epi_archive) -is_epi_archive(archive_cases_dv_subset) # TRUE +is_epi_archive2(jhu_csse_daily_subset) # FALSE (this is an epi_df, not epi_archive) +is_epi_archive2(archive_cases_dv_subset_2) # TRUE # By default, grouped_epi_archives don't count as epi_archives, as they may # support a different set of operations from regular `epi_archives`. This # behavior can be controlled by `grouped_okay`. -grouped_archive <- archive_cases_dv_subset$group_by(geo_value) -is_epi_archive(grouped_archive) # FALSE -is_epi_archive(grouped_archive, grouped_okay = TRUE) # TRUE +grouped_archive <- archive_cases_dv_subset_2 \%>\% group_by(geo_value) +is_epi_archive2(grouped_archive) # FALSE +is_epi_archive2(grouped_archive, grouped_okay = TRUE) # TRUE } \seealso{ diff --git a/tests/testthat/test-archive_new.R b/tests/testthat/test-archive_new.R index f2d0bde5..98f708d7 100644 --- a/tests/testthat/test-archive_new.R +++ b/tests/testthat/test-archive_new.R @@ -6,7 +6,7 @@ test_that("first input must be a data.frame", { ) }) -dt <- archive_cases_dv_subset$DT +dt <- archive_cases_dv_subset_2$DT test_that("data.frame must contain geo_value, time_value and version columns", { expect_error(as_epi_archive2(select(dt, -geo_value), compactify = FALSE), diff --git a/tests/testthat/test-compactify.R b/tests/testthat/test-compactify.R index 4400c94a..58e97884 100644 --- a/tests/testthat/test-compactify.R +++ b/tests/testthat/test-compactify.R @@ -2,7 +2,7 @@ library(epiprocess) library(data.table) library(dplyr) -dt <- archive_cases_dv_subset$DT +dt <- archive_cases_dv_subset_2$DT dt <- filter(dt, geo_value == "ca") %>% filter(version <= "2020-06-15") %>% select(-case_rate_7d_av) diff --git a/tests/testthat/test-compactify_new.R b/tests/testthat/test-compactify_new.R index f2887eaf..cd53913d 100644 --- a/tests/testthat/test-compactify_new.R +++ b/tests/testthat/test-compactify_new.R @@ -2,7 +2,7 @@ library(epiprocess) library(data.table) library(dplyr) -dt <- archive_cases_dv_subset$DT +dt <- archive_cases_dv_subset_2$DT dt <- filter(dt, geo_value == "ca") %>% filter(version <= "2020-06-15") %>% select(-case_rate_7d_av) diff --git a/tests/testthat/test-epix_merge_new.R b/tests/testthat/test-epix_merge_new.R index 594b7b5e..10041dbb 100644 --- a/tests/testthat/test-epix_merge_new.R +++ b/tests/testthat/test-epix_merge_new.R @@ -1,8 +1,6 @@ test_that("epix_merge requires forbids on invalid `y`", { - ea <- archive_cases_dv_subset$DT %>% - as_epi_archive2() %>% - clone() %>% - suppressWarnings() + ea <- archive_cases_dv_subset_2 %>% + clone() expect_error(epix_merge2(ea, data.frame(x = 1))) }) diff --git a/tests/testthat/test-epix_slide_new.R b/tests/testthat/test-epix_slide_new.R index f748231a..49ef5e41 100644 --- a/tests/testthat/test-epix_slide_new.R +++ b/tests/testthat/test-epix_slide_new.R @@ -800,7 +800,7 @@ test_that("`epix_slide2` can access objects inside of helper functions", { archive_haystack %>% epix_slide2(has_needle = time_value_needle %in% time_value, before = 365000L) } expect_error( - helper(suppressWarnings(as_epi_archive2(archive_cases_dv_subset$DT)), as.Date("2021-01-01")), + helper(archive_cases_dv_subset_2, as.Date("2021-01-01")), NA ) expect_error( diff --git a/tests/testthat/test-methods-epi_archive_new.R b/tests/testthat/test-methods-epi_archive_new.R index a267ba58..eb2c14be 100644 --- a/tests/testthat/test-methods-epi_archive_new.R +++ b/tests/testthat/test-methods-epi_archive_new.R @@ -1,9 +1,7 @@ library(dplyr) -ea <- archive_cases_dv_subset$DT %>% - as_epi_archive2() %>% - clone() %>% - suppressWarnings() +ea <- archive_cases_dv_subset_2 %>% + clone() ea2_data <- tibble::tribble( ~geo_value, ~time_value, ~version, ~cases,