Skip to content

Commit

Permalink
working on the grouped versions
Browse files Browse the repository at this point in the history
  • Loading branch information
dajmcdon committed Jun 20, 2024
1 parent 740d0ea commit 15c00bf
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
2 changes: 1 addition & 1 deletion R/methods-epi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ as_tibble.epi_df <- function(x, ...) {
# Decaying drops the class and metadata. `as_tibble.grouped_df` drops the
# grouping and should be called by `NextMethod()` in the current design.
# See #223 for discussion of alternatives.
if (attr(x, "no_decay_to_tibble") %||% FALSE) return(x)
if (attr(x, "no_decay_to_tibble") %||% FALSE) return(ungroup(x))
decay_epi_df(NextMethod())
}

Expand Down
11 changes: 9 additions & 2 deletions tests/testthat/test-as_tibble-decay.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
test_that("as_tibble checks an attr to avoid decay to tibble", {
edf <- jhu_csse_daily_subset
expect_s3_class(as_tibble(edf), c("tbl_df", "tbl", "data.frame"))
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
attr(edf, "no_decay_to_tibble") <- TRUE
expect_s3_class(as_tibble(edf), c("epi_df", "tbl_df", "tbl", "data.frame"))
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
})

test_that("as_tibble ungroups if needed", {
edf <- jhu_csse_daily_subset %>% group_by(geo_value)
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
attr(edf, "no_decay_to_tibble") <- TRUE
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
})

0 comments on commit 15c00bf

Please sign in to comment.