diff --git a/R/census_geo_api.R b/R/census_geo_api.R index 6b64854..4676ba5 100644 --- a/R/census_geo_api.R +++ b/R/census_geo_api.R @@ -112,7 +112,7 @@ census_geo_api <- function( message(paste("County ", county, " of ", length(county_list), ": ", county_list[county], sep = "")) region_county <- paste("for=tract:*&in=state:", state.fips, "+county:", county_list[county], sep = "") get_census_api(data_url = census_data_url, key = key, var.names = unlist(vars), region = region_county, retry) - }) + }, .progress = TRUE) } else { message('There were no intersecting counties in your voter.file data (tract)') } @@ -192,7 +192,7 @@ census_geo_api <- function( region_block <- paste("for=block:*&in=state:", state.fips, "+county:", county_list[county], "+tract:", tract_list[tract], sep = "") get_census_api(census_data_url, key = key, var.names = unlist(vars), region = region_block, retry) - }) + }, .progress = TRUE) } ) message("\n") # new line for progress bar diff --git a/tests/testthat/test-census_helper_v2.R b/tests/testthat/test-census_helper_v2.R index 3da6501..a30ce17 100644 --- a/tests/testthat/test-census_helper_v2.R +++ b/tests/testthat/test-census_helper_v2.R @@ -10,6 +10,7 @@ test_that("Fails if 'precinct' is set as the geo var",{ skip_on_cran() set.seed(42) data(voters) + future::plan(future::multisession) census <- readRDS(test_path("data/new_census_table_NJ_2020.rds")) expect_error( census_helper_new( @@ -32,6 +33,7 @@ test_that("helper returns verified census tract data",{ skip_on_cran() set.seed(42) data(voters) + future::plan(future::multisession) census <- readRDS(test_path("data/new_census_table_NJ_2020.rds")) x <- census_helper_new( voter.file = voters, @@ -56,6 +58,7 @@ test_that("New tables and legacy tables return equal race predictions",{ skip_on_cran() set.seed(42) data(voters) + future::plan(future::multisession) # legacy redistricting table census <- readRDS(test_path("data/census_test_nj_block_2020.rds")) x <- census_helper_new( diff --git a/tests/testthat/test-get_census_data.R b/tests/testthat/test-get_census_data.R index f2e2aa9..f43eece 100644 --- a/tests/testthat/test-get_census_data.R +++ b/tests/testthat/test-get_census_data.R @@ -5,7 +5,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { r <- suppressMessages(get_census_data( key = NULL, state = c("DC"), - census.geo = "block", + census.geo = "block" )) expect_named(r$DC, c("state", "age", "sex", "year", "block", "tract", "county")) @@ -13,6 +13,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { }) test_that("Census block_group download works", { + future::plan(future::multisession) r <- suppressMessages(get_census_data( key = NULL, state = "RI", @@ -23,6 +24,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { }) test_that("Census tract download works", { + future::plan(future::multisession) r <- suppressMessages(get_census_data( key = NULL, state = c("NY"), @@ -35,6 +37,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { }) test_that("Census county download works", { + future::plan(future::multisession) r <- suppressMessages(get_census_data( key = NULL, state = "NJ", @@ -46,6 +49,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { }) test_that("Census place download works", { + future::plan(future::multisession) r <- suppressMessages(get_census_data( key = NULL, state = "RI", diff --git a/tests/testthat/test-rollup.R b/tests/testthat/test-rollup.R index 655d535..bef93cc 100644 --- a/tests/testthat/test-rollup.R +++ b/tests/testthat/test-rollup.R @@ -9,8 +9,8 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { )) r_tract_from_block <- r$DE$block |> - group_by(tract) |> - summarize( + dplyr::group_by(tract) |> + dplyr::summarize( sum_whi = sum(r_whi), sum_bla = sum(r_bla), sum_his = sum(r_his), @@ -19,9 +19,9 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { ) r_tract_level <- r$DE$tract |> - select(tract, r_whi:r_oth) |> - group_by(tract) |> - summarize( + dplyr::select(tract, r_whi:r_oth) |> + dplyr::group_by(tract) |> + dplyr::summarize( sum_whi = sum(r_whi), sum_bla = sum(r_bla), sum_his = sum(r_his), @@ -30,9 +30,9 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { ) r_county_from_tract <- r$DE$tract |> - select(county, r_whi:r_oth) |> - group_by(county) |> - summarize( + dplyr::select(county, r_whi:r_oth) |> + dplyr::group_by(county) |> + dplyr::summarize( sum_whi = sum(r_whi), sum_bla = sum(r_bla), sum_his = sum(r_his), @@ -41,9 +41,9 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { ) r_county_level <- r$DE$county |> - select(county, r_whi:r_oth) |> - group_by(county) |> - summarize( + dplyr::select(county, r_whi:r_oth) |> + dplyr::group_by(county) |> + dplyr::summarize( sum_whi = sum(r_whi), sum_bla = sum(r_bla), sum_his = sum(r_his), @@ -138,15 +138,15 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { )) r_sum_from_block <- r$AK$block |> - select(r_whi:r_fem_23_oth) |> + dplyr::select(r_whi:r_fem_23_oth) |> apply(2, sum) r_sum_from_tract <- r$AK$tract |> - select(r_whi:r_fem_23_oth) |> + dplyr::select(r_whi:r_fem_23_oth) |> apply(2, sum) r_sum_from_county <- r$AK$county |> - select(r_whi:r_fem_23_oth) |> + dplyr::select(r_whi:r_fem_23_oth) |> apply(2, sum) r_zcta_level <- suppressMessages(get_census_data( @@ -158,7 +158,7 @@ if(Sys.getenv("CENSUS_API_KEY") != "") { )) r_sum_from_zcta <- r_zcta_level$AK$zcta |> - select(r_whi:r_fem_23_oth) |> + dplyr::select(r_whi:r_fem_23_oth) |> apply(2, sum) expect_true(