@@ -2,36 +2,34 @@ test_that("`key_colnames` on non-`epi_df`-like tibbles works as expected", {
22 k1k2_tbl <- tibble :: tibble(k1 = 1 , k2 = 1 )
33
44 expect_equal(
5- key_colnames(k1k2_tbl , geo_keys = character (0L ), time_keys = character (0L ), other_keys = c(" k1" , " k2" )),
5+ key_colnames(k1k2_tbl , geo_keys = character (), time_keys = character (), other_keys = c(" k1" , " k2" )),
66 c(" k1" , " k2" )
77 )
8- # `geo_keys` and `time_keys` are optional, and, in this case, inferred to be absent:
9- expect_equal(
10- key_colnames(k1k2_tbl , other_keys = c(" k1" , " k2" )),
11- c(" k1" , " k2" )
12- )
13- # but `other_keys` is mandatory:
14- expect_error(
15- key_colnames(k1k2_tbl )
16- )
8+ # `geo_keys`, `other_keys`, `time_keys` are mandatory:
9+ expect_error(key_colnames(k1k2_tbl , other_keys = c(" k1" , " k2" ), time_keys = character ()),
10+ regexp = ' "geo_keys" is missing' )
11+ expect_error(key_colnames(k1k2_tbl , geo_keys = character (), time_keys = character ()),
12+ regexp = ' "other_keys" is missing' )
13+ expect_error(key_colnames(k1k2_tbl , geo_keys = character (), other_keys = c(" k1" , " k2" )),
14+ regexp = ' "time_keys" is missing' )
1715
1816 # Manually specifying keys that aren't there is an error:
1917 expect_error(
20- key_colnames(k1k2_tbl , geo_keys = " bogus" , other_keys = c(" k1" , " k2" )),
18+ key_colnames(k1k2_tbl , geo_keys = " bogus" , other_keys = c(" k1" , " k2" ), time_keys = character () ),
2119 class = " epiprocess__key_colnames__keys_not_in_colnames"
2220 )
2321 expect_error(
24- key_colnames(k1k2_tbl , time_keys = " bogus" , other_keys = c( " k1 " , " k2 " )),
22+ key_colnames(k1k2_tbl , other_keys = " bogus" , geo_keys = character (), time_keys = character ( )),
2523 class = " epiprocess__key_colnames__keys_not_in_colnames"
2624 )
2725 expect_error(
28- key_colnames(k1k2_tbl , other_keys = " bogus" ),
26+ key_colnames(k1k2_tbl , time_keys = " bogus" , geo_keys = character (), other_keys = c( " k1 " , " k2 " ) ),
2927 class = " epiprocess__key_colnames__keys_not_in_colnames"
3028 )
3129
3230 # We can specify non-`epi_df`-like geo keys:
3331 expect_equal(
34- key_colnames(k1k2_tbl , geo_keys = c(" k1" , " k2" ), other_keys = character (0L )),
32+ key_colnames(k1k2_tbl , geo_keys = c(" k1" , " k2" ), other_keys = character (), time_keys = character ( )),
3533 c(" k1" , " k2" )
3634 )
3735})
@@ -42,28 +40,35 @@ test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
4240 gat_tbl <- tibble :: tibble(geo_value = 1 , age_group = 1 , time_value = 1 )
4341 gat_edf <- as_epi_df(gat_tbl , other_keys = " age_group" , as_of = 2 )
4442
45- # For tbl: `geo_keys` and `time_keys` are optional, and, in this case,
46- # inferred to be (just) `geo_value` and (just) `time_value`:
43+ # For tbl: we must provide all key naming arguments:
4744 expect_equal(
48- key_colnames(gat_tbl , other_keys = " age_group" ),
45+ key_colnames(gat_tbl , geo_keys = " geo_value " , other_keys = " age_group" , time_keys = " time_value " ),
4946 c(" geo_value" , " age_group" , " time_value" )
5047 )
51- # and edfs give something compatible:
48+ # given same inputs, compatible edfs give something compatible:
5249 expect_equal(
53- key_colnames(gat_edf , other_keys = " age_group" ),
50+ key_colnames(gat_edf , geo_keys = " geo_value " , other_keys = " age_group" , time_keys = " time_value " ),
5451 c(" geo_value" , " age_group" , " time_value" )
5552 )
56- # though edfs don't have to specify the `other_keys` :
53+ # though edfs don't have to specify the key settings :
5754 expect_equal(
5855 key_colnames(gat_edf ),
5956 c(" geo_value" , " age_group" , " time_value" )
6057 )
6158 # and they will balk if we write something intended to work for both tbls and
62- # edfs but mis-specify the `other_keys`:
59+ # edfs but mis-specify something:
60+ expect_error(
61+ key_colnames(gat_edf , geo_keys = character (0L )),
62+ class = " epiprocess__key_colnames__mismatched_geo_keys"
63+ )
6364 expect_error(
6465 key_colnames(gat_edf , other_keys = character (0L )),
6566 class = " epiprocess__key_colnames__mismatched_other_keys"
6667 )
68+ expect_error(
69+ key_colnames(gat_edf , time_keys = character (0L )),
70+ class = " epiprocess__key_colnames__mismatched_time_keys"
71+ )
6772
6873 # edfs also won't let us specify nonstandard geotime keys:
6974 expect_error(
@@ -77,11 +82,11 @@ test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
7782
7883 # We can exclude keys:
7984 expect_equal(
80- key_colnames(gat_tbl , other_keys = " age_group" , exclude = c(" time_value" )),
85+ key_colnames(gat_tbl , geo_keys = " geo_value " , other_keys = " age_group" , time_keys = " time_value " , exclude = c(" time_value" )),
8186 c(" geo_value" , " age_group" )
8287 )
8388 expect_equal(
84- key_colnames(gat_tbl , other_keys = " age_group" , exclude = c(" geo_value" , " time_value" )),
89+ key_colnames(gat_tbl , geo_keys = " geo_value " , other_keys = " age_group" , time_keys = " time_value " , exclude = c(" geo_value" , " time_value" )),
8590 c(" age_group" )
8691 )
8792 expect_equal(
@@ -95,7 +100,7 @@ test_that("`key_colnames` on `epi_df`s and similar tibbles works as expected", {
95100
96101 # Using `extra_keys =` is soft-deprecated and routes to `other_keys =`:
97102 expect_warning(
98- gat_tbl_extra_keys_res <- key_colnames(gat_tbl , extra_keys = " age_group" ),
103+ gat_tbl_extra_keys_res <- key_colnames(gat_tbl , geo_keys = " geo_value " , time_keys = " time_value " , extra_keys = " age_group" ),
99104 class = " lifecycle_warning_deprecated"
100105 )
101106 expect_equal(gat_tbl_extra_keys_res , c(" geo_value" , " age_group" , " time_value" ))
0 commit comments