Skip to content

Commit 09ad0dc

Browse files
committed
refactor: changes from review
* remove is_epi_archive and delete in epix_slide * simplify group_by_drop_default * filter and move library calls to testthat.R
1 parent 123b9a8 commit 09ad0dc

14 files changed

+8
-86
lines changed

NAMESPACE

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export(filter)
6464
export(group_by)
6565
export(group_modify)
6666
export(growth_rate)
67-
export(is_epi_archive)
6867
export(is_epi_df)
6968
export(is_grouped_epi_archive)
7069
export(key_colnames)
@@ -94,6 +93,7 @@ importFrom(checkmate,checkInt)
9493
importFrom(checkmate,check_atomic)
9594
importFrom(checkmate,check_data_frame)
9695
importFrom(checkmate,check_names)
96+
importFrom(checkmate,expect_class)
9797
importFrom(checkmate,test_set_equal)
9898
importFrom(checkmate,test_subset)
9999
importFrom(checkmate,vname)

R/archive.R

-25
Original file line numberDiff line numberDiff line change
@@ -652,31 +652,6 @@ group_by.epi_archive <- function(.data, ..., .add = FALSE, .drop = dplyr::group_
652652
}
653653

654654

655-
#' Test for `epi_archive` format
656-
#'
657-
#' @param x An object.
658-
#' @param grouped_okay Optional; Boolean; should a `grouped_epi_archive` also
659-
#' count? Default is `FALSE`.
660-
#' @return `TRUE` if the object inherits from `epi_archive`.
661-
#'
662-
#' @export
663-
#' @examples
664-
#' is_epi_archive(jhu_csse_daily_subset) # FALSE (this is an epi_df, not epi_archive)
665-
#' is_epi_archive(archive_cases_dv_subset) # TRUE
666-
#'
667-
#' # By default, grouped_epi_archives don't count as epi_archives, as they may
668-
#' # support a different set of operations from regular `epi_archives`. This
669-
#' # behavior can be controlled by `grouped_okay`.
670-
#' grouped_archive <- archive_cases_dv_subset %>% group_by(geo_value)
671-
#' is_epi_archive(grouped_archive) # FALSE
672-
#' is_epi_archive(grouped_archive, grouped_okay = TRUE) # TRUE
673-
#'
674-
#' @seealso [`is_grouped_epi_archive`]
675-
is_epi_archive <- function(x, grouped_okay = FALSE) {
676-
inherits(x, "epi_archive") || grouped_okay && inherits(x, "grouped_epi_archive")
677-
}
678-
679-
680655
#' Clone an `epi_archive` object.
681656
#'
682657
#' @param x An `epi_archive` object.

R/epiprocess.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#' @importFrom checkmate assert assert_scalar assert_data_frame anyMissing
88
#' assert_logical assert_list assert_character assert_class
99
#' assert_int assert_numeric check_data_frame vname check_atomic
10-
#' anyInfinite test_subset test_set_equal checkInt
10+
#' anyInfinite test_subset test_set_equal checkInt expect_class
1111
#' @importFrom cli cli_abort cli_warn
1212
#' @importFrom rlang %||%
1313
#' @name epiprocess

R/grouped_epi_archive.R

+1-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ group_by.grouped_epi_archive <- function(
157157
#'
158158
#' @export
159159
group_by_drop_default.grouped_epi_archive <- function(.tbl) {
160-
x <- .tbl
161-
x$private$drop
160+
.tbl$private$drop
162161
}
163162

164163

R/methods-epi_archive.R

-3
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,6 @@ epix_slide <- function(
797797
as_list_col = FALSE,
798798
names_sep = "_",
799799
all_versions = FALSE) {
800-
if (!is_epi_archive(x, grouped_okay = TRUE)) {
801-
cli_abort("`x` must be of class `epi_archive` or `grouped_epi_archive`.")
802-
}
803800
UseMethod("epix_slide")
804801
}
805802

man/is_epi_archive.Rd

-35
This file was deleted.

tests/testthat.R

+2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
library(testthat)
22
library(epiprocess)
33

4+
library(dplyr)
5+
46
test_check("epiprocess")

tests/testthat/test-archive.R

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library(dplyr)
2-
31
test_that("first input must be a data.frame", {
42
expect_error(as_epi_archive(c(1, 2, 3), compactify = FALSE),
53
regexp = "Must be of type 'data.frame'."

tests/testthat/test-autoplot.R

-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
library(dplyr)
2-
31
d <- as.Date("2020-01-01")
4-
52
raw_df_chr <- dplyr::bind_rows(
63
dplyr::tibble(geo_value = "ak", time_value = d + 1:5, value = "a"),
74
dplyr::tibble(geo_value = "al", time_value = d + 1:5, value = "d")

tests/testthat/test-compactify.R

-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
library(epiprocess)
2-
library(data.table)
3-
library(dplyr)
4-
51
dt <- archive_cases_dv_subset$DT
62
dt <- filter(dt, geo_value == "ca") %>%
73
filter(version <= "2020-06-15") %>%

tests/testthat/test-correlation.R

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library(tibble)
2-
31
test_that("epi_cor throws an error for a non-epi_df for its first argument", {
42
expect_error(epi_cor(1:10, 1, 1))
53
expect_error(epi_cor(data.frame(x = 1:10), 1, 1))

tests/testthat/test-data.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
test_that("`archive_cases_dv_subset` is formed successfully", {
2-
expect_true(is_epi_archive(archive_cases_dv_subset))
2+
expect_class(archive_cases_dv_subset, "epi_archive")
33
})
44

55
test_that("`delayed_assign_with_unregister_awareness` works as expected on good promises", {

tests/testthat/test-epix_slide.R

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
library(dplyr)
2-
31
test_that("epix_slide only works on an epi_archive", {
42
expect_error(epix_slide(data.frame(x = 1)))
53
})
@@ -506,7 +504,7 @@ test_that("epix_as_of and epix_slide with long enough window are compatible", {
506504

507505
test_that("epix_slide `f` is passed an ungrouped `epi_archive` when `all_versions=TRUE`", {
508506
slide_fn <- function(x, gk, rtv) {
509-
expect_true(is_epi_archive(x))
507+
expect_class(x, "epi_archive")
510508
return(NA)
511509
}
512510

tests/testthat/test-methods-epi_archive.R

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
library(dplyr)
2-
31
ea <- archive_cases_dv_subset
4-
52
ea2_data <- tibble::tribble(
63
~geo_value, ~time_value, ~version, ~cases,
74
"ca", "2020-06-01", "2020-06-01", 1,
@@ -104,7 +101,7 @@ test_that("epix_truncate_version_after returns the same grouping type as input e
104101

105102
ea_as_of <- ea2 %>%
106103
epix_truncate_versions_after(max_version = as.Date("2020-06-04"))
107-
expect_true(is_epi_archive(ea_as_of, grouped_okay = FALSE))
104+
expect_class(ea_as_of, "epi_archive")
108105

109106
ea2_grouped <- ea2 %>% group_by(geo_value)
110107

0 commit comments

Comments
 (0)