From ff3dfae096a10b26f494a2d6427cafdafe83b14f Mon Sep 17 00:00:00 2001 From: dsweber2 Date: Tue, 16 Jan 2024 12:48:46 -0800 Subject: [PATCH] doc: minor annotations --- tests/testthat/test-methods-epi_df.R | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/testthat/test-methods-epi_df.R b/tests/testthat/test-methods-epi_df.R index 6be7e89b..aeb08ced 100644 --- a/tests/testthat/test-methods-epi_df.R +++ b/tests/testthat/test-methods-epi_df.R @@ -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) @@ -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)