Skip to content

Commit 34acd7e

Browse files
committed
Make extra_keys = into soft "deprecation" of a different behavior
to ease epipredict transition.
1 parent 839e921 commit 34acd7e

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: epiprocess
33
Title: Tools for basic signal processing in epidemiology
4-
Version: 0.9.4
4+
Version: 0.9.6
55
Authors@R: c(
66
person("Jacob", "Bien", role = "ctb"),
77
person("Logan", "Brooks", , "[email protected]", role = c("aut", "cre")),

R/key_colnames.R

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,16 @@
2727
#' @keywords internal
2828
#' @export
2929
key_colnames <- function(x, ..., exclude = character()) {
30-
UseMethod("key_colnames")
30+
provided_args <- rlang::call_args_names(rlang::call_match())
31+
if ("extra_keys" %in% provided_args) {
32+
lifecycle::deprecate_soft("0.9.6", "key_colnames(extra_keys=)", "key_colnames(other_keys=)")
33+
redispatch <- function(..., extra_keys) {
34+
key_colnames(..., other_keys = extra_keys)
35+
}
36+
redispatch(x, ..., exclude = exclude)
37+
} else {
38+
UseMethod("key_colnames")
39+
}
3140
}
3241

3342
#' @rdname key_colnames
@@ -44,7 +53,7 @@ key_colnames.data.frame <- function(x, ...,
4453
assert_character(time_keys)
4554
assert_character(other_keys)
4655
assert_character(exclude)
47-
keys = c(geo_keys, other_keys, time_keys)
56+
keys <- c(geo_keys, other_keys, time_keys)
4857
if (!all(keys %in% names(x))) {
4958
cli_abort(c(
5059
"Some of the specified key columns aren't present in `x`",
@@ -67,11 +76,13 @@ key_colnames.epi_df <- function(x, ...,
6776
check_dots_empty0(...)
6877
if (!identical(geo_keys, "geo_value")) {
6978
cli_abort('If `x` is an `epi_df`, then `geo_keys` must be `"geo_value"`',
70-
class = "epiprocess__key_colnames__mismatched_geo_keys")
79+
class = "epiprocess__key_colnames__mismatched_geo_keys"
80+
)
7181
}
7282
if (!identical(time_keys, "time_value")) {
7383
cli_abort('If `x` is an `epi_df`, then `time_keys` must be `"time_value"`',
74-
class = "epiprocess__key_colnames__mismatched_time_keys")
84+
class = "epiprocess__key_colnames__mismatched_time_keys"
85+
)
7586
}
7687
expected_other_keys <- attr(x, "metadata")$other_keys
7788
if (is.null(other_keys)) {

tests/testthat/test-key_colnames.R

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
test_that("`key_colnames` on non-`epi_df`-like tibbles works as expected", {
2+
withr::local_options(list(lifecycle_verbosity = "warning")) # for extra_keys tests
23

34
k1k2_tbl <- tibble::tibble(k1 = 1, k2 = 1)
45

@@ -35,11 +36,9 @@ test_that("`key_colnames` on non-`epi_df`-like tibbles works as expected", {
3536
key_colnames(k1k2_tbl, geo_keys = c("k1", "k2"), other_keys = character(0L)),
3637
c("k1", "k2")
3738
)
38-
3939
})
4040

4141
test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
42-
4342
gat_tbl <- tibble::tibble(geo_value = 1, age_group = 1, time_value = 1)
4443
gat_edf <- as_epi_df(gat_tbl, other_keys = "age_group", as_of = 2)
4544

@@ -76,16 +75,6 @@ test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
7675
class = "epiprocess__key_colnames__mismatched_time_keys"
7776
)
7877

79-
# For either class, `extra_keys` is not accepted:
80-
expect_error(
81-
key_colnames(gat_tbl, extra_keys = "age_group"),
82-
class = "rlib_error_dots_nonempty"
83-
)
84-
expect_error(
85-
key_colnames(gat_edf, extra_keys = "age_group"),
86-
class = "rlib_error_dots_nonempty"
87-
)
88-
8978
# We can exclude keys:
9079
expect_equal(
9180
key_colnames(gat_tbl, other_keys = "age_group", exclude = c("time_value")),
@@ -104,10 +93,22 @@ test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
10493
c("age_group")
10594
)
10695

96+
# Using `extra_keys =` is soft-deprecated and routes to `other_keys =`:
97+
expect_warning(
98+
gat_tbl_extra_keys_res <- key_colnames(gat_tbl, extra_keys = "age_group"),
99+
class = "lifecycle_warning_deprecated"
100+
)
101+
expect_equal(gat_tbl_extra_keys_res, c("geo_value", "age_group", "time_value"))
102+
103+
expect_warning(
104+
gat_edf_extra_keys_exclude_res <-
105+
key_colnames(gat_edf, extra_keys = "age_group", exclude = c("geo_value", "time_value")),
106+
class = "lifecycle_warning_deprecated"
107+
)
108+
expect_equal(gat_edf_extra_keys_exclude_res, c("age_group"))
107109
})
108110

109111
test_that("`key_colnames` on tsibbles works as expected", {
110-
111112
k1k2i_tsbl <- tsibble::tsibble(k1 = 1, k2 = 1, i = 1, key = c(k1, k2), index = i)
112113

113114
# Normal operation:
@@ -133,11 +134,9 @@ test_that("`key_colnames` on tsibbles works as expected", {
133134
key_colnames(k1k2i_tsbl %>% tsibble::index_by(fake_coarser_i = i)),
134135
class = "epiprocess__key_colnames__incomplete_reindexing_operation"
135136
)
136-
137137
})
138138

139139
test_that("`key_colnames` on `epi_archive`s works as expected", {
140-
141140
gatv_ea <- tibble(geo_value = 1, age_group = 1, time_value = 1, version = 2) %>%
142141
as_epi_archive(other_keys = "age_group")
143142

@@ -168,5 +167,4 @@ test_that("`key_colnames` on `epi_archive`s works as expected", {
168167
key_colnames(gatv_ea, exclude = c("version", "time_value")),
169168
c("geo_value", "age_group")
170169
)
171-
172170
})

0 commit comments

Comments
 (0)