Skip to content

Commit 15c00bf

Browse files
committed
working on the grouped versions
1 parent 740d0ea commit 15c00bf

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

R/methods-epi_df.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ as_tibble.epi_df <- function(x, ...) {
1212
# Decaying drops the class and metadata. `as_tibble.grouped_df` drops the
1313
# grouping and should be called by `NextMethod()` in the current design.
1414
# See #223 for discussion of alternatives.
15-
if (attr(x, "no_decay_to_tibble") %||% FALSE) return(x)
15+
if (attr(x, "no_decay_to_tibble") %||% FALSE) return(ungroup(x))
1616
decay_epi_df(NextMethod())
1717
}
1818

tests/testthat/test-as_tibble-decay.R

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
test_that("as_tibble checks an attr to avoid decay to tibble", {
22
edf <- jhu_csse_daily_subset
3-
expect_s3_class(as_tibble(edf), c("tbl_df", "tbl", "data.frame"))
3+
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
44
attr(edf, "no_decay_to_tibble") <- TRUE
5-
expect_s3_class(as_tibble(edf), c("epi_df", "tbl_df", "tbl", "data.frame"))
5+
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
6+
})
7+
8+
test_that("as_tibble ungroups if needed", {
9+
edf <- jhu_csse_daily_subset %>% group_by(geo_value)
10+
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
11+
attr(edf, "no_decay_to_tibble") <- TRUE
12+
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
613
})

0 commit comments

Comments
 (0)