Skip to content

Commit 3430f0e

Browse files
authored
Merge pull request #507 from cmu-delphi/lcb/remove-select-epi-df
Remove `select.epi_df`
2 parents 7f8c4a7 + 8debd4c commit 3430f0e

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Imports:
2929
checkmate,
3030
cli,
3131
data.table,
32-
dplyr (>= 1.0.0),
32+
dplyr (>= 1.0.8),
3333
genlasso,
3434
ggplot2,
3535
glue,

NAMESPACE

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ S3method(next_after,integer)
3838
S3method(print,epi_archive)
3939
S3method(print,epi_df)
4040
S3method(print,grouped_epi_archive)
41-
S3method(select,epi_df)
4241
S3method(summary,epi_df)
4342
S3method(ungroup,epi_df)
4443
S3method(ungroup,grouped_epi_archive)

R/group_by_epi_df_methods.R

-8
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,3 @@
33
# `epi_df`s. It would be nice if there were a way to replace these with a
44
# generic core that automatically fixed all misbehaving methods; see
55
# brainstorming within Issue #223.
6-
7-
#' @importFrom dplyr select
8-
#' @export
9-
select.epi_df <- function(.data, ...) {
10-
selected <- NextMethod(.data)
11-
might_decay <- reclass(selected, attr(selected, "metadata"))
12-
return(dplyr_reconstruct(might_decay, might_decay))
13-
}

tests/testthat/test-epi_slide.R

+4-4
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ test_that("`ref_time_values` + `all_rows = TRUE` works", {
434434
),
435435
basic_full_result %>%
436436
dplyr::mutate(slide_value = dplyr::if_else(time_value %in% (test_date + c(2L, 8L)),
437-
slide_value, NA_integer_
437+
slide_value, NA_real_ # (`^` outputs numeric)
438438
))
439439
)
440440

@@ -472,7 +472,7 @@ test_that("`ref_time_values` + `all_rows = TRUE` works", {
472472
),
473473
basic_mean_result %>%
474474
dplyr::mutate(slide_value_value = dplyr::if_else(time_value %in% (test_date + c(2L, 8L)),
475-
slide_value, NA_integer_
475+
slide_value, NA_real_
476476
)) %>%
477477
select(-slide_value)
478478
)
@@ -498,7 +498,7 @@ test_that("`ref_time_values` + `all_rows = TRUE` works", {
498498
),
499499
basic_full_result %>%
500500
dplyr::mutate(slide_value = dplyr::if_else(time_value %in% (test_date + c(2L, 8L)),
501-
slide_value, NA_integer_
501+
slide_value, NA_real_
502502
)) %>%
503503
dplyr::rename(slide_value_value = slide_value)
504504
)
@@ -584,7 +584,7 @@ test_that("`ref_time_values` + `all_rows = TRUE` works", {
584584
unnest(slide_value, names_sep = "_"),
585585
basic_full_result %>%
586586
dplyr::mutate(slide_value = dplyr::if_else(time_value %in% (test_date + c(2L, 8L)),
587-
slide_value, NA_integer_
587+
slide_value, NA_real_
588588
)) %>%
589589
dplyr::rename(slide_value_value = slide_value)
590590
)

tests/testthat/test-methods-epi_df.R

+20-1
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,30 @@ test_that("Renaming columns while grouped gives appropriate colnames and metadat
173173
expect_identical(attr(renamed_gedf1, "metadata")$other_keys, c("age_group"))
174174
# renaming using select
175175
renamed_gedf2 <- gedf %>%
176-
as_epi_df(additional_metadata = list(other_keys = "age")) %>%
177176
select(geo_value, time_value, age_group = age, value)
178177
expect_identical(renamed_gedf1, renamed_gedf2)
179178
})
180179

180+
test_that("Additional `select` on `epi_df` tests", {
181+
edf <- tibble::tibble(geo_value = "ak", time_value = as.Date("2020-01-01"), age = 1, value = 1) %>%
182+
as_epi_df(additional_metadata = list(other_keys = "age"))
183+
184+
# Dropping a non-geo_value epikey column doesn't decay, though maybe it
185+
# should, since you'd expect that to possibly result in multiple rows per
186+
# epikey (though not in this toy case), and while we don't require that, we
187+
# sort of expect it:
188+
edf_not_decayed <- edf %>%
189+
select(geo_value, time_value, value)
190+
expect_class(edf_not_decayed, "epi_df")
191+
expect_identical(attr(edf_not_decayed, "metadata")$other_keys, character(0L))
192+
193+
# Dropping geo_value does decay:
194+
edf_decayed <- edf %>%
195+
select(age, time_value, value)
196+
expect_false(inherits(edf_decayed, "epi_df"))
197+
expect_identical(attr(edf_decayed, "metadata"), NULL)
198+
})
199+
181200
test_that("complete.epi_df works", {
182201
start_date <- as.Date("2020-01-01")
183202
daily_edf <- tibble::tribble(

0 commit comments

Comments
 (0)