Skip to content

Commit

Permalink
Add support for 2000 places per walkerke#129
Browse files Browse the repository at this point in the history
Includes test
  • Loading branch information
elipousson committed Apr 10, 2024
1 parent 0f41d25 commit 315d46f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions R/places.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ places <- function(state = NULL, cb = FALSE, year = NULL, ...) {
return(p)
}

year <- set_tigris_year(year)
year <- set_tigris_year(year, min_year = 2000)

if (year > 2000 && year < 2010) {
abort("`year` must be 2000 or greater than 2010.")
}

if (is.null(state)) {
if (year > 2018 && cb) {
Expand All @@ -39,13 +43,14 @@ places <- function(state = NULL, cb = FALSE, year = NULL, ...) {
}

if (cb) {
url_fmt <- "GENZ%s/shp/cb_%s_%s_place_500k"
url <- url_tiger("GENZ%s/shp/cb_%s_%s_place_500k", year, year, state)
} else if (year %in% c(2000, 2010)) {
suf <- substr(year, 3, 4)
url <- url_tiger("TIGER2010/PLACE/%s/tl_2010_%s_place%s", year, state, suf)
} else {
url_fmt <- "TIGER%s/PLACE/tl_%s_%s_place"
url <- url_tiger("TIGER%s/PLACE/tl_%s_%s_place", year, year, state)
}

url <- url_tiger(url_fmt, year, year, state)

return(load_tiger(url, tigris_type = "place", ...))

}
Expand Down
4 changes: 3 additions & 1 deletion tests/testthat/test-places.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
test_that("places errors", {
expect_error(places(year = 2018))
expect_error(places(year = 2017, cb = TRUE))
expect_error(places(year = 2009, state = "WY"))
})

test_that("places works", {
withr::local_options(list(tigris_use_cache = TRUE))
state <- "WY"
expect_s3_class(places(year = 2019, cb = TRUE), "sf")
expect_s3_class(places(state = c(state, "SD")), "sf")
expect_s3_class(places(state = state, year = 2010), "sf")

expect_s3_class(places(state = c(state, "SD")), "sf")
state_places <- places(state = state)
expect_s3_class(state_places, "sf")

Expand Down

0 comments on commit 315d46f

Please sign in to comment.