Skip to content

Commit 3d65e57

Browse files
dajmcdondshemetov
authored andcommitted
remove additional_metadata from archive as well
1 parent 8b99ce4 commit 3d65e57

File tree

8 files changed

+30
-72
lines changed

8 files changed

+30
-72
lines changed

R/archive.R

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,6 @@ NULL
212212
#' that should be considered key variables (in the language of `data.table`)
213213
#' apart from "geo_value", "time_value", and "version". Typical examples
214214
#' are "age" or more granular geographies.
215-
#' @param additional_metadata List of additional metadata to attach to the
216-
#' `epi_archive` object. The metadata will have the `geo_type` field; named
217-
#' entries from the passed list or will be included as well.
218215
#' @param compactify Optional; Boolean. `TRUE` will remove some
219216
#' redundant rows, `FALSE` will not, and missing or `NULL` will remove
220217
#' redundant rows, but issue a warning. See more information at `compactify`.
@@ -295,7 +292,6 @@ new_epi_archive <- function(
295292
geo_type,
296293
time_type,
297294
other_keys,
298-
additional_metadata,
299295
compactify,
300296
clobberable_versions_start,
301297
versions_end,
@@ -353,7 +349,6 @@ new_epi_archive <- function(
353349
geo_type = geo_type,
354350
time_type = time_type,
355351
other_keys = other_keys,
356-
additional_metadata = additional_metadata,
357352
clobberable_versions_start = clobberable_versions_start,
358353
versions_end = versions_end
359354
),
@@ -426,7 +421,6 @@ is_locf <- function(vec, tolerance) { # nolint: object_usage_linter
426421
validate_epi_archive <- function(
427422
x,
428423
other_keys,
429-
additional_metadata,
430424
compactify,
431425
clobberable_versions_start,
432426
versions_end) {
@@ -437,9 +431,6 @@ validate_epi_archive <- function(
437431
if (any(c("geo_value", "time_value", "version") %in% other_keys)) {
438432
cli_abort("`other_keys` cannot contain \"geo_value\", \"time_value\", or \"version\".")
439433
}
440-
if (any(names(additional_metadata) %in% c("geo_type", "time_type"))) {
441-
cli_warn("`additional_metadata` names overlap with existing metadata fields \"geo_type\" or \"time_type\".")
442-
}
443434

444435
# Conduct checks and apply defaults for `compactify`
445436
assert_logical(compactify, len = 1, any.missing = FALSE, null.ok = TRUE)
@@ -489,7 +480,6 @@ as_epi_archive <- function(
489480
geo_type = deprecated(),
490481
time_type = deprecated(),
491482
other_keys = character(0L),
492-
additional_metadata = list(),
493483
compactify = NULL,
494484
clobberable_versions_start = NA,
495485
.versions_end = max_version_with_row_in(x), ...,
@@ -521,11 +511,10 @@ as_epi_archive <- function(
521511
time_type <- guess_time_type(x$time_value)
522512

523513
validate_epi_archive(
524-
x, other_keys, additional_metadata,
525-
compactify, clobberable_versions_start, versions_end
514+
x, other_keys, compactify, clobberable_versions_start, versions_end
526515
)
527516
new_epi_archive(
528-
x, geo_type, time_type, other_keys, additional_metadata,
517+
x, geo_type, time_type, other_keys,
529518
compactify, clobberable_versions_start, versions_end
530519
)
531520
}
@@ -554,7 +543,7 @@ print.epi_archive <- function(x, ..., class = TRUE, methods = TRUE) {
554543
c(
555544
">" = if (class) "An `epi_archive` object, with metadata:",
556545
"i" = if (length(setdiff(key(x$DT), c("geo_value", "time_value", "version"))) > 0) {
557-
"Non-standard DT keys: {setdiff(key(x$DT), c('geo_value', 'time_value', 'version'))}"
546+
"Other DT keys: {setdiff(key(x$DT), c('geo_value', 'time_value', 'version'))}"
558547
},
559548
"i" = if (nrow(x$DT) != 0L) {
560549
"Min/max time values: {min(x$DT$time_value)} / {max(x$DT$time_value)}"
@@ -690,7 +679,8 @@ print.epi_archive <- function(x, ..., class = TRUE, methods = TRUE) {
690679
#' @export
691680
#'
692681
#' @aliases grouped_epi_archive
693-
group_by.epi_archive <- function(.data, ..., .add = FALSE, .drop = dplyr::group_by_drop_default(.data)) {
682+
group_by.epi_archive <- function(.data, ..., .add = FALSE,
683+
.drop = dplyr::group_by_drop_default(.data)) {
694684
# `add` makes no difference; this is an ungrouped `epi_archive`.
695685
detailed_mutate <- epix_detailed_restricted_mutate(.data, ...)
696686
assert_logical(.drop)

R/methods-epi_archive.R

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,6 @@ epix_as_of <- function(x, max_version, min_time_value = -Inf, all_versions = FAL
114114
as_of = max_version,
115115
other_keys = other_keys
116116
)
117-
if (length(x$additional_metadata) != 0L) {
118-
attr(as_of_epi_df, "additional_metadata") <- x$additional_metadata
119-
}
120117

121118
return(as_of_epi_df)
122119
}
@@ -240,9 +237,8 @@ epix_fill_through_version <- function(x, fill_versions_end,
240237
#' Default here is `TRUE`.
241238
#' @return the resulting `epi_archive`
242239
#'
243-
#' @details In all cases, `additional_metadata` will be an empty list, and
244-
#' `clobberable_versions_start` will be set to the earliest version that could
245-
#' be clobbered in either input archive.
240+
#' @details In all cases, `clobberable_versions_start` will be set to the
241+
#' earliest version that could be clobbered in either input archive.
246242
#'
247243
#' @examples
248244
#' # Example 1
@@ -331,18 +327,6 @@ epix_merge <- function(x, y,
331327
cli_abort("`x` and `y` must share data type on their `time_value` column.")
332328
}
333329

334-
if (length(x$additional_metadata) != 0L) {
335-
cli_warn("x$additional_metadata won't appear in merge result",
336-
class = "epiprocess__epix_merge_ignores_additional_metadata"
337-
)
338-
}
339-
if (length(y$additional_metadata) != 0L) {
340-
cli_warn("y$additional_metadata won't appear in merge result",
341-
class = "epiprocess__epix_merge_ignores_additional_metadata"
342-
)
343-
}
344-
result_additional_metadata <- list()
345-
346330
result_clobberable_versions_start <-
347331
if (all(is.na(c(x$clobberable_versions_start, y$clobberable_versions_start)))) {
348332
NA # (any type of NA is fine here)
@@ -508,7 +492,6 @@ epix_merge <- function(x, y,
508492
return(as_epi_archive(
509493
result_dt[], # clear data.table internal invisibility flag if set
510494
other_keys = setdiff(key(result_dt), c("geo_value", "time_value", "version")),
511-
additional_metadata = result_additional_metadata,
512495
# It'd probably be better to pre-compactify before the merge, and might be
513496
# guaranteed not to be necessary to compactify the merge result if the
514497
# inputs are already compactified, but at time of writing we don't have

man/epi_archive.Rd

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

man/epix_merge.Rd

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

tests/testthat/test-archive.R

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,6 @@ test_that("other_keys cannot contain names geo_value, time_value or version", {
7777
)
7878
})
7979

80-
test_that("Warning thrown when other_metadata contains overlapping names with geo_type field", {
81-
expect_warning(as_epi_archive(archive_data, additional_metadata = list(geo_type = 1), compactify = FALSE),
82-
regexp = "`additional_metadata` names overlap with existing metadata fields"
83-
)
84-
expect_warning(as_epi_archive(archive_data, additional_metadata = list(time_type = 1), compactify = FALSE),
85-
regexp = "`additional_metadata` names overlap with existing metadata fields"
86-
)
87-
})
8880

8981
test_that("epi_archives are correctly instantiated with a variety of data types", {
9082
d <- as.Date("2020-01-01")
@@ -98,22 +90,22 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
9890

9991
ea1 <- as_epi_archive(df, compactify = FALSE)
10092
expect_equal(key(ea1$DT), c("geo_value", "time_value", "version"))
101-
expect_equal(ea1$additional_metadata, list())
93+
expect_null(ea1$additional_metadata)
10294

103-
ea2 <- as_epi_archive(df, other_keys = "value", additional_metadata = list(value = df$value), compactify = FALSE)
95+
ea2 <- as_epi_archive(df, other_keys = "value", compactify = FALSE)
10496
expect_equal(key(ea2$DT), c("geo_value", "time_value", "value", "version"))
105-
expect_equal(ea2$additional_metadata, list(value = df$value))
97+
expect_null(ea2$additional_metadata)
10698

10799
# Tibble
108100
tib <- tibble::tibble(df, code = "x")
109101

110102
ea3 <- as_epi_archive(tib, compactify = FALSE)
111103
expect_equal(key(ea3$DT), c("geo_value", "time_value", "version"))
112-
expect_equal(ea3$additional_metadata, list())
104+
expect_null(ea3$additional_metadata)
113105

114-
ea4 <- as_epi_archive(tib, other_keys = "code", additional_metadata = list(value = df$value), compactify = FALSE)
106+
ea4 <- as_epi_archive(tib, other_keys = "code", compactify = FALSE)
115107
expect_equal(key(ea4$DT), c("geo_value", "time_value", "code", "version"))
116-
expect_equal(ea4$additional_metadata, list(value = df$value))
108+
expect_null(ea4$additional_metadata)
117109

118110
# Keyed data.table
119111
kdt <- data.table::data.table(
@@ -128,12 +120,12 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
128120
ea5 <- as_epi_archive(kdt, compactify = FALSE)
129121
# Key from data.table isn't absorbed when as_epi_archive is used
130122
expect_equal(key(ea5$DT), c("geo_value", "time_value", "version"))
131-
expect_equal(ea5$additional_metadata, list())
123+
expect_null(ea5$additional_metadata)
132124

133-
ea6 <- as_epi_archive(kdt, other_keys = "value", additional_metadata = list(value = df$value), compactify = FALSE)
125+
ea6 <- as_epi_archive(kdt, other_keys = "value", compactify = FALSE)
134126
# Mismatched keys, but the one from as_epi_archive overrides
135127
expect_equal(key(ea6$DT), c("geo_value", "time_value", "value", "version"))
136-
expect_equal(ea6$additional_metadata, list(value = df$value))
128+
expect_null(ea6$additional_metadata)
137129

138130
# Unkeyed data.table
139131
udt <- data.table::data.table(
@@ -146,11 +138,11 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
146138

147139
ea7 <- as_epi_archive(udt, compactify = FALSE)
148140
expect_equal(key(ea7$DT), c("geo_value", "time_value", "version"))
149-
expect_equal(ea7$additional_metadata, list())
141+
expect_null(ea7$additional_metadata)
150142

151-
ea8 <- as_epi_archive(udt, other_keys = "code", additional_metadata = list(value = df$value), compactify = FALSE)
143+
ea8 <- as_epi_archive(udt, other_keys = "code", compactify = FALSE)
152144
expect_equal(key(ea8$DT), c("geo_value", "time_value", "code", "version"))
153-
expect_equal(ea8$additional_metadata, list(value = df$value))
145+
expect_null(ea8$additional_metadata)
154146

155147
# epi_df
156148
edf1 <- jhu_csse_daily_subset %>%
@@ -159,11 +151,11 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
159151

160152
ea9 <- as_epi_archive(edf1, compactify = FALSE)
161153
expect_equal(key(ea9$DT), c("geo_value", "time_value", "version"))
162-
expect_equal(ea9$additional_metadata, list())
154+
expect_null(ea9$additional_metadata)
163155

164-
ea10 <- as_epi_archive(edf1, other_keys = "code", additional_metadata = list(value = df$value), compactify = FALSE)
156+
ea10 <- as_epi_archive(edf1, other_keys = "code", compactify = FALSE)
165157
expect_equal(key(ea10$DT), c("geo_value", "time_value", "code", "version"))
166-
expect_equal(ea10$additional_metadata, list(value = df$value))
158+
expect_null(ea10$additional_metadata)
167159

168160
# Keyed epi_df
169161
edf2 <- data.frame(
@@ -180,11 +172,11 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
180172

181173
ea11 <- as_epi_archive(edf2, compactify = FALSE)
182174
expect_equal(key(ea11$DT), c("geo_value", "time_value", "version"))
183-
expect_equal(ea11$additional_metadata, list())
175+
expect_null(ea11$additional_metadata)
184176

185-
ea12 <- as_epi_archive(edf2, other_keys = "misc", additional_metadata = list(value = df$misc), compactify = FALSE)
177+
ea12 <- as_epi_archive(edf2, other_keys = "misc", compactify = FALSE)
186178
expect_equal(key(ea12$DT), c("geo_value", "time_value", "misc", "version"))
187-
expect_equal(ea12$additional_metadata, list(value = df$misc))
179+
expect_null(ea12$additional_metadata)
188180
})
189181

190182
test_that("`epi_archive` rejects nonunique keys", {

tests/testthat/test-epix_merge.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,8 @@ test_that("epix_merge forbids and warns on metadata and naming issues", {
177177
),
178178
regexp = "overlapping.*names"
179179
)
180+
181+
skip("Additional metadata is no longer used, not tested.")
180182
expect_warning(
181183
epix_merge(
182184
as_epi_archive(tibble::tibble(geo_value = "ak", time_value = test_date, version = test_date + 1L, x_value = 1L),

tests/testthat/test-methods-epi_df.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ test_that("Renaming columns gives appropriate colnames and metadata", {
150150
expect_identical(attr(renamed_edf1, "metadata")$other_keys, c("age_group"))
151151
# renaming using select
152152
renamed_edf2 <- edf %>%
153-
as_epi_df(additional_metadata = list(other_keys = "age")) %>%
153+
as_epi_df(other_keys = "age") %>%
154154
select(geo_value, time_value, age_group = age, value)
155155
expect_identical(renamed_edf1, renamed_edf2)
156156
})

vignettes/archive.Rmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@ The following pieces of metadata are included as fields in an `epi_archive`
119119
object:
120120

121121
* `geo_type`: the type for the geo values.
122-
* `additional_metadata`: list of additional metadata for the data archive.
123122

124123
Metadata for an `epi_archive` object `x` can be accessed (and altered) directly,
125124
as in `x$geo_type`, etc. Just like `as_epi_df()`, the function

0 commit comments

Comments
 (0)