Skip to content

Commit 740094e

Browse files
author
admin
committed
Updated test additional_metadata & the passing of that into as_epi_df()
1 parent 5b4d6d1 commit 740094e

File tree

3 files changed

+13
-16
lines changed

3 files changed

+13
-16
lines changed

R/epi_df.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ as_epi_df.tbl_df = function(x, geo_type, time_type, as_of,
222222
}
223223

224224
new_epi_df(x, geo_type, time_type, as_of,
225-
additional_metadata = list(), ...)
225+
additional_metadata, ...)
226226
}
227227

228228
#' @method as_epi_df data.frame

R/methods-epi_df.R

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,9 @@ summary.epi_df = function(object, ...) {
9898

9999
cn <- names(res)
100100
nr <- vctrs::vec_size(x)
101-
not_epi_df <- !("time_value" %in% cn) || !("geo_value" %in% cn) ||
102-
vctrs::vec_size(res) > nr || any(i > nr)
101+
not_epi_df <- (!("time_value" %in% cn) || !("geo_value" %in% cn)
102+
|| vctrs::vec_size(res) > nr || any(i > nr))
103+
103104
if (not_epi_df) return(tibble::as_tibble(res))
104105

105106
# Case when i is numeric and there are duplicate values in it
@@ -115,7 +116,8 @@ summary.epi_df = function(object, ...) {
115116
geo_type = att_x$geo_type,
116117
time_type = att_x$time_type,
117118
as_of = att_x$as_of,
118-
additional_metadata = list(att_x$additional_metadata))
119+
additional_metadata =
120+
att_x[!(names(att_x) %in% c("geo_type", "time_type", "as_of"))])
119121
}
120122

121123
#' `dplyr` verbs

tests/testthat/test-methods-epi_df.R

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ toy_epi_df <- tibble::tibble(
77
length.out = 5
88
), times = 2),
99
geo_value = rep(c("ca", "hi"), each = 5),
10-
additional_key_val = as.factor(rep(1:2, times = 5)),
11-
) %>% epiprocess::as_epi_df()
10+
indicator_var = as.factor(rep(1:2, times = 5)),
11+
) %>% epiprocess::as_epi_df(additional_metadata =
12+
c(other_keys = "indicator_var"))
1213

13-
attributes(toy_epi_df)$metadata$additional_metadata <-
14-
list(additional_key_name = "additional_key_type")
1514
att_toy = attr(toy_epi_df, "metadata")
1615

1716
test_that("head and tail do not drop the epi_df class", {
@@ -23,13 +22,11 @@ test_that("head and tail do not drop the epi_df class", {
2322
expect_identical(att_head$geo_type, att_toy$geo_type)
2423
expect_identical(att_head$time_type, att_toy$time_type)
2524
expect_identical(att_head$as_of, att_toy$as_of)
26-
expect_identical(att_head$additional_key_name,
27-
att_toy$additional_metadata$additional_key_name)
25+
expect_identical(att_head$other_keys, att_toy$other_keys)
2826
expect_identical(att_tail$geo_type, att_toy$geo_type)
2927
expect_identical(att_tail$time_type, att_toy$time_type)
3028
expect_identical(att_tail$as_of, att_toy$as_of)
31-
expect_identical(att_tail$additional_key_name,
32-
att_toy$additional_metadata$additional_key_name)
29+
expect_identical(att_tail$other_keys, att_toy$other_keys)
3330
})
3431

3532

@@ -45,8 +42,7 @@ test_that("subsetting drops or does not drop the epi_df class appropriately", {
4542
expect_identical(att_row_subset$geo_type, att_toy$geo_type)
4643
expect_identical(att_row_subset$time_type, att_toy$time_type)
4744
expect_identical(att_row_subset$as_of, att_toy$as_of)
48-
expect_identical(att_row_subset$additional_key_name,
49-
att_toy$additional_metadata$additional_key_name)
45+
expect_identical(att_row_subset$other_keys, att_toy$other_keys)
5046

5147
# Col subset - shouldn't be an epi_df
5248
col_subset = toy_epi_df[, 2:3]
@@ -73,7 +69,6 @@ test_that("subsetting drops or does not drop the epi_df class appropriately", {
7369
expect_identical(att_row_col_subset2$geo_type, att_toy$geo_type)
7470
expect_identical(att_row_col_subset2$time_type, att_toy$time_type)
7571
expect_identical(att_row_col_subset2$as_of, att_toy$as_of)
76-
expect_identical(att_row_col_subset2$additional_key_name,
77-
att_toy$additional_metadata$additional_key_name)
72+
expect_identical(att_row_col_subset2$other_keys, att_toy$other_keys)
7873

7974
})

0 commit comments

Comments
 (0)