From 96578d1e338b2e950c183eacaa0b69dea300b35f Mon Sep 17 00:00:00 2001 From: wcurrangroome Date: Mon, 30 Sep 2024 14:56:52 -0400 Subject: [PATCH 1/2] new indicators --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index b69f499..ee64816 100644 --- a/.gitignore +++ b/.gitignore @@ -8,4 +8,5 @@ inst/doc *.csv /doc/ /Meta/ -*.rds +.rds +/inst From 9b425117f77b268876e5b61b5726fd2cbeab4477 Mon Sep 17 00:00:00 2001 From: wcurrangroome Date: Mon, 30 Sep 2024 14:58:20 -0400 Subject: [PATCH 2/2] new indicators --- R/compile_acs_data.R | 6 ++++++ R/list_acs_variables.R | 4 ++++ tests/testthat/test-compile_acs_data.R | 26 ++++++++++++++------------ 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/R/compile_acs_data.R b/R/compile_acs_data.R index 5c33146..618331a 100644 --- a/R/compile_acs_data.R +++ b/R/compile_acs_data.R @@ -135,6 +135,12 @@ internal_compute_acs_variables = function(.data) { .fns = ~ safe_divide(.x, get( dplyr::cur_column() %>% stringr::str_replace("owner", "renter_owner") )), .names = "{.col}_percent"), + ## units in structure + dplyr::across( + .cols = c(dplyr::matches("^units_in_structure"), -dplyr::matches("universe|householder")), + .fns = ~ safe_divide(.x, units_in_structure_universe), + .names = "{.col}_percent"), + ## units in structure, both tenures ## (sums) dplyr::across( ## summing renter- and owner-occupied estimates diff --git a/R/list_acs_variables.R b/R/list_acs_variables.R index 6452041..dc87d28 100644 --- a/R/list_acs_variables.R +++ b/R/list_acs_variables.R @@ -222,12 +222,16 @@ list_acs_variables = function(year = "2022") { ## race-specific tables, just remove the "_", a la: select_variables(variable_name = "B18101") ####----HOUSING---#### + ## TENURE (by race) select_variables("B25003"), ## TENURE BY OCCUPANTS PER ROOM select_variables("B25014"), + ## UNITS IN STRUCTURE + select_variables("B25024"), + ## TENURE BY UNITS IN STRUCTURE select_variables("B25032"), diff --git a/tests/testthat/test-compile_acs_data.R b/tests/testthat/test-compile_acs_data.R index 372d64d..338865d 100644 --- a/tests/testthat/test-compile_acs_data.R +++ b/tests/testthat/test-compile_acs_data.R @@ -1,17 +1,19 @@ # message("Update test data prior to testing, as needed.") # -# df = compile_acs_data( -# variables = NULL, -# years = c(2022), -# geography = "tract", -# states = c("CA", "TX"), -# counties = NULL, -# spatial = FALSE) -# -# codebook = attr(df, "codebook") -# -# saveRDS(object = df, file = file.path("inst", "test-data", "test_data_2024-08-24.rds")) -# saveRDS(codebook, file = file.path("inst", "test-data", "codebook_2024-08-24.rds")) +df = compile_acs_data( + variables = NULL, + years = c(2022), + geography = "tract", + states = c("CA", "TX"), + counties = NULL, + spatial = FALSE) + +codebook = attr(df, "codebook") + +saveRDS(object = df, file = file.path("inst", "test-data", "test_data_2024-08-24.rds")) +saveRDS(codebook, file = file.path("inst", "test-data", "codebook_2024-08-24.rds")) + +df %>% dplyr::select(dplyr::matches("mobile")) %>% colnames() ####----Tests----#### # All percentages have no values greater than one and no values less than zero