Skip to content

Commit 1be9df7

Browse files
committed
Make epi_archive key order geo !!!other time version
1 parent 540549d commit 1be9df7

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Pre-1.0.0 numbering scheme: 0.x will indicate releases, while 0.x.y will indicat
88

99
- `new_epi_archive()`'s `x` argument has been replaced with a `data_table`
1010
argument, which must be a `data.table` with the key already set appropriately.
11+
The `key()` of its `DT` will also now place `other_keys` before rather than after
12+
`"time_value"`.
1113

1214
## Bug fixes
1315

R/archive.R

+3-3
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ new_epi_archive <- function(
291291
if (any(c("geo_value", "time_value", "version") %in% other_keys)) {
292292
cli_abort("`other_keys` cannot contain \"geo_value\", \"time_value\", or \"version\".")
293293
}
294-
assert_true(identical(key(data_table), c("geo_value", "time_value", other_keys, "version")))
294+
assert_true(identical(key(data_table), c("geo_value", other_keys, "time_value", "version")))
295295
validate_version_bound(clobberable_versions_start, data_table, na_ok = TRUE)
296296
validate_version_bound(versions_end, data_table, na_ok = FALSE)
297297

@@ -315,7 +315,7 @@ new_epi_archive <- function(
315315
validate_epi_archive <- function(x) {
316316
assert_class(x, "epi_archive")
317317

318-
ukey_vars1 <- c("geo_value", "time_value", x$other_keys, "version")
318+
ukey_vars1 <- c("geo_value", x$other_keys, "time_value", "version")
319319
ukey_vars2 <- key(x$DT)
320320
if (!identical(ukey_vars1, ukey_vars2)) {
321321
cli_abort(c("`data.table::key(x$DT)` not as expected",
@@ -523,7 +523,7 @@ as_epi_archive <- function(
523523
x <- guess_column_name(x, "version", version_column_names())
524524

525525
# Convert to data.table:
526-
key_vars <- c("geo_value", "time_value", other_keys, "version")
526+
key_vars <- c("geo_value", other_keys, "time_value", "version")
527527
if (x_already_copied) {
528528
setDT(x, key = key_vars)
529529
} else {

tests/testthat/test-archive.R

+6-6
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
9292
expect_equal(key(ea1$DT), c("geo_value", "time_value", "version"))
9393

9494
ea2 <- as_epi_archive(df, other_keys = "value", compactify = FALSE)
95-
expect_equal(key(ea2$DT), c("geo_value", "time_value", "value", "version"))
95+
expect_equal(key(ea2$DT), c("geo_value", "value", "time_value", "version"))
9696

9797
# Tibble
9898
tib <- tibble::tibble(df, code = "x")
@@ -101,7 +101,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
101101
expect_equal(key(ea3$DT), c("geo_value", "time_value", "version"))
102102

103103
ea4 <- as_epi_archive(tib, other_keys = "code", compactify = FALSE)
104-
expect_equal(key(ea4$DT), c("geo_value", "time_value", "code", "version"))
104+
expect_equal(key(ea4$DT), c("geo_value", "code", "time_value", "version"))
105105

106106
# Keyed data.table
107107
kdt <- data.table::data.table(
@@ -119,7 +119,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
119119

120120
ea6 <- as_epi_archive(kdt, other_keys = "value", compactify = FALSE)
121121
# Mismatched keys, but the one from as_epi_archive overrides
122-
expect_equal(key(ea6$DT), c("geo_value", "time_value", "value", "version"))
122+
expect_equal(key(ea6$DT), c("geo_value", "value", "time_value", "version"))
123123

124124
# Unkeyed data.table
125125
udt <- data.table::data.table(
@@ -134,7 +134,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
134134
expect_equal(key(ea7$DT), c("geo_value", "time_value", "version"))
135135

136136
ea8 <- as_epi_archive(udt, other_keys = "code", compactify = FALSE)
137-
expect_equal(key(ea8$DT), c("geo_value", "time_value", "code", "version"))
137+
expect_equal(key(ea8$DT), c("geo_value", "code", "time_value", "version"))
138138

139139
# epi_df
140140
edf1 <- cases_deaths_subset %>%
@@ -145,7 +145,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
145145
expect_equal(key(ea9$DT), c("geo_value", "time_value", "version"))
146146

147147
ea10 <- as_epi_archive(edf1, other_keys = "code", compactify = FALSE)
148-
expect_equal(key(ea10$DT), c("geo_value", "time_value", "code", "version"))
148+
expect_equal(key(ea10$DT), c("geo_value", "code", "time_value", "version"))
149149

150150
# Keyed epi_df
151151
edf2 <- data.frame(
@@ -164,7 +164,7 @@ test_that("epi_archives are correctly instantiated with a variety of data types"
164164
expect_equal(key(ea11$DT), c("geo_value", "time_value", "version"))
165165

166166
ea12 <- as_epi_archive(edf2, other_keys = "misc", compactify = FALSE)
167-
expect_equal(key(ea12$DT), c("geo_value", "time_value", "misc", "version"))
167+
expect_equal(key(ea12$DT), c("geo_value", "misc", "time_value", "version"))
168168
})
169169

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

0 commit comments

Comments
 (0)