Skip to content

Commit a63a465

Browse files
committed
done
1 parent 9a3d950 commit a63a465

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

R/methods-epi_df.R

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,11 @@ 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) {
16-
metadata <- attr(x, "metadata")
17-
x <- NextMethod()
18-
return(reclass(x, metadata))
15+
if (attr(x, "decay_to_tibble") %||% TRUE) {
16+
return(decay_epi_df(NextMethod()))
1917
}
20-
decay_epi_df(NextMethod())
18+
metadata <- attr(x, "metadata")
19+
reclass(NextMethod(), metadata)
2120
}
2221

2322
#' Convert to tsibble format

tests/testthat/test-as_tibble-decay.R

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
test_that("as_tibble checks an attr to avoid decay to tibble", {
22
edf <- jhu_csse_daily_subset
33
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
4-
attr(edf, "no_decay_to_tibble") <- TRUE
4+
attr(edf, "decay_to_tibble") <- TRUE
5+
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
6+
attr(edf, "decay_to_tibble") <- FALSE
57
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
68
})
79

810
test_that("as_tibble ungroups if needed", {
911
edf <- jhu_csse_daily_subset %>% group_by(geo_value)
1012
# removes the grouped_df class
11-
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
12-
attr(edf, "no_decay_to_tibble") <- TRUE
13+
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
14+
attr(edf, "decay_to_tibble") <- TRUE
15+
expect_identical(class(as_tibble(edf)), c("tbl_df", "tbl", "data.frame"))
16+
attr(edf, "decay_to_tibble") <- FALSE
1317
# removes grouped_df but not `epi_df`
1418
expect_identical(class(as_tibble(edf)), c("epi_df", "tbl_df", "tbl", "data.frame"))
1519
})

0 commit comments

Comments
 (0)