Skip to content

Commit

Permalink
doc: minor annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
dsweber2 committed Jan 16, 2024
1 parent 0bf702f commit ff3dfae
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/testthat/test-methods-epi_df.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,13 @@ test_that("Metadata and grouping are dropped by `as_tibble`", {
test_that("Renaming columns gives appropriate colnames and metadata", {
edf <- tibble::tibble(geo_value = 1, time_value = 1, age = 1, value = 1) %>%
as_epi_df(additional_metadata = list(other_keys = "age"))
# renaming using base R
renamed_edf1 <- edf %>%
`[`(c("geo_value", "time_value", "age", "value")) %>%
`names<-`(c("geo_value", "time_value", "age_group", "value"))
expect_identical(names(renamed_edf1), c("geo_value", "time_value", "age_group", "value"))
expect_identical(attr(renamed_edf1, "metadata")$other_keys, c("age_group"))
# renaming using select
renamed_edf2 <- edf %>%
as_epi_df(additional_metadata = list(other_keys = "age")) %>%
select(geo_value, time_value, age_group = age, value)
Expand All @@ -143,13 +145,17 @@ test_that("Renaming columns while grouped gives appropriate colnames and metadat
gedf <- tibble::tibble(geo_value = 1, time_value = 1, age = 1, value = 1) %>%
as_epi_df(additional_metadata = list(other_keys = "age")) %>%
group_by(geo_value)
# renaming using base R
renamed_gedf1 <- gedf %>%
`[`(c("geo_value", "time_value", "age", "value")) %>%
`names<-`(c("geo_value", "time_value", "age_group", "value"))
# tets type preservation
expect_true(inherits(renamed_gedf1, "epi_df"))
expect_true(inherits(renamed_gedf1, "grouped_df"))
# the names are right
expect_identical(names(renamed_gedf1), c("geo_value", "time_value", "age_group", "value"))
expect_identical(attr(renamed_gedf1, "metadata")$other_keys, c("age_group"))
# renaming using select
renamed_gedf2 <- gedf %>%
as_epi_df(additional_metadata = list(other_keys = "age")) %>%
select(geo_value, time_value, age_group = age, value)
Expand Down

0 comments on commit ff3dfae

Please sign in to comment.