Skip to content

Commit

Permalink
Should dedupe regions in multi_geo_* function calls as well
Browse files Browse the repository at this point in the history
  • Loading branch information
camille-s committed Dec 22, 2023
1 parent c4e6ebb commit e0df439
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
4 changes: 4 additions & 0 deletions R/census_helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ census_state <- function(src, table, year, state, dataset, key, sleep, ...) {
# needs name of estimate/value column
census_regions <- function(src, table, year, regions, state, value, dataset, key, sleep, ...) {
Sys.sleep(sleep)

# get unique regions but keep names
regions <- regions[unique(names(regions))]

region_df <- tibble::enframe(regions, value = "town")
region_df <- tidyr::unnest(region_df, town)
fetch <- census_towns(src, table, year, "all", "all", state, dataset, key, 0, ...)
Expand Down
1 change: 0 additions & 1 deletion R/multi_geo_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ multi_geo_prep <- function(src,
"i" = "Note that these columns should now be given as strings, not bare names."))
}


# validate county names, convert to 5-digit fips
drop_counties <- is.null(counties)

Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-multi_geo_fetch.R
Original file line number Diff line number Diff line change
Expand Up @@ -99,3 +99,9 @@ test_that("multi_geo_* handles survey codes", {
expect_error(multi_test("decennial", "P1", 2020, dataset = "sf1"))
})

test_that("multi_geo_* deduplicates regions", {
skip_on_ci()
p1 <- multi_geo_acs("B01003", regions = regions[c("Greater New Haven", "Greater New Haven", "Greater Waterbury")], towns = NULL, counties = NULL)
p2 <- multi_geo_acs("B01003", regions = regions[c("Greater New Haven", "Greater Waterbury")], towns = NULL, counties = NULL)
expect_identical(p1, p2)
})

0 comments on commit e0df439

Please sign in to comment.