Skip to content

Commit

Permalink
feat: add a epi_df attribute that avoids the decay. See #467
Browse files Browse the repository at this point in the history
  • Loading branch information
dajmcdon committed Jun 20, 2024
1 parent 7fd2119 commit b7f36e0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions R/methods-epi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +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)
decay_epi_df(NextMethod())
}

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-as_tibble-decay.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
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"))
attr(edf, "no_decay_to_tibble") <- TRUE
expect_s3_class(as_tibble(edf), c("epi_df", "tbl_df", "tbl", "data.frame"))
})

0 comments on commit b7f36e0

Please sign in to comment.