From fb371a5afdb25f09ae48069aa21167a1be698c33 Mon Sep 17 00:00:00 2001 From: wcurrangroome Date: Tue, 8 Oct 2024 00:11:00 -0400 Subject: [PATCH] adjusting age over 64% --- .gitignore | 2 +- R/compile_acs_data.R | 6 +++--- tests/testthat/test-compile_acs_data.R | 26 ++++++++++++-------------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index ee64816..a1655a1 100644 --- a/.gitignore +++ b/.gitignore @@ -8,5 +8,5 @@ inst/doc *.csv /doc/ /Meta/ -.rds +*.rds /inst diff --git a/R/compile_acs_data.R b/R/compile_acs_data.R index 618331a..48da037 100644 --- a/R/compile_acs_data.R +++ b/R/compile_acs_data.R @@ -85,11 +85,11 @@ internal_compute_acs_variables = function(.data) { ####----AGE----#### ## creating combined, male and female counts by age group named, e.g., age_15_17_years dplyr::across( - .cols = dplyr::matches("sex_by_age_female_.*years$"), + .cols = dplyr::matches("sex_by_age_female_.*years($|_over$)"), .fns = ~ .x + get( dplyr::cur_column() %>% stringr::str_replace("female", "male")), .names = "{stringr::str_replace(string = .col, pattern = 'sex_by_age_female_', replacement = 'age_')}"), dplyr::across( - .cols = dplyr::matches("^age.*years$"), + .cols = dplyr::matches("^age.*years($|_over$)"), .fns = ~ safe_divide(.x, sex_by_age_universe), .names = "{.col}_percent")) %>% @@ -100,7 +100,7 @@ internal_compute_acs_variables = function(.data) { rowSums(dplyr::select(., age_under_5_years, age_5_9_years, age_10_14_years, age_15_17_years)), sex_by_age_universe), age_over_64_percent = safe_divide( - rowSums(dplyr::select(., dplyr::matches("age_(6(5|7)|7|8).*_years$"))), + rowSums(dplyr::select(., dplyr::matches("age_(6(5|7)|7|8).*_years($|_over$)"))), sex_by_age_universe), ####----DISABILITY----#### diff --git a/tests/testthat/test-compile_acs_data.R b/tests/testthat/test-compile_acs_data.R index 338865d..372d64d 100644 --- a/tests/testthat/test-compile_acs_data.R +++ b/tests/testthat/test-compile_acs_data.R @@ -1,19 +1,17 @@ # 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 %>% dplyr::select(dplyr::matches("mobile")) %>% colnames() +# 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")) ####----Tests----#### # All percentages have no values greater than one and no values less than zero