Skip to content

Commit

Permalink
support place-level 2023 population estimates
Browse files Browse the repository at this point in the history
  • Loading branch information
walkerke committed May 16, 2024
1 parent aab2900 commit 52fc427
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
Package: tidycensus
Type: Package
Title: Load US Census Boundary and Attribute Data as 'tidyverse' and 'sf'-Ready Data Frames
Version: 1.6.3
Version: 1.6.4
Authors@R: c(
person(given = "Kyle", family = "Walker", email="[email protected]", role=c("aut", "cre")),
person(given = "Matt", family = "Herman", email = "[email protected]", role = "aut"),
person(given = "Kris", family = "Eberwein", email = "[email protected]", role = "ctb"))
Date: 2024-03-20
Date: 2024-05-16
URL: https://walker-data.com/tidycensus/
BugReports: https://github.com/walkerke/tidycensus/issues
Description: An integrated R interface to several United States Census Bureau
Expand Down Expand Up @@ -41,4 +41,4 @@ Suggests:
survey,
srvyr,
terra
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
20 changes: 12 additions & 8 deletions R/estimates.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,12 @@ get_estimates <- function(geography = c("us", "region", "division", "state", "co
}

if (vintage > 2022) {
rlang::abort("The Characteristics dataset has not yet been released for vintages beyond 2022.")
rlang::abort("The Characteristics dataset has not yet been released for vintages beyond 2022")
}

if (geography == "state") {

state_raw <- suppressMessages(readr::read_csv("https://www2.census.gov/programs-surveys/popest/datasets/2020-2022/state/asrh/sc-est2022-alldata6.csv"))
state_raw <- suppressMessages(readr::read_csv(sprintf("https://www2.census.gov/programs-surveys/popest/datasets/2020-%s/state/asrh/sc-est%s-alldata6.csv", vintage, vintage)))

if (!is.null(state)) {
state <- validate_state(state)
Expand All @@ -125,7 +125,7 @@ get_estimates <- function(geography = c("us", "region", "division", "state", "co
NAME:SEX,
HISP = ORIGIN,
RACE:AGE,
POPESTIMATE2020:POPESTIMATE2022) %>%
dplyr::contains("POPESTIMATE")) %>%
dplyr::mutate(AGEGROUP = dplyr::case_when(
AGE %in% 0:4 ~ 1,
AGE %in% 5:9 ~ 2,
Expand All @@ -147,7 +147,7 @@ get_estimates <- function(geography = c("us", "region", "division", "state", "co
AGE == 85 ~ 18
)) %>%
tidyr::pivot_longer(
POPESTIMATE2020:POPESTIMATE2022,
dplyr::contains("POPESTIMATE"),
names_to = "year",
values_to = "value",
names_prefix = "POPESTIMATE"
Expand All @@ -156,6 +156,10 @@ get_estimates <- function(geography = c("us", "region", "division", "state", "co

} else if (geography == "county") {

if (vintage > 2022) {
rlang::abort("The county characteristics dataset for this vintage has not yet been released.")
}

if (!is.null(state)) {
state <- validate_state(state)

Expand Down Expand Up @@ -482,11 +486,11 @@ get_estimates <- function(geography = c("us", "region", "division", "state", "co

} else if (geography == "place") {

if (vintage > 2022) {
rlang::abort("The most recent PEP release for this geography is 2022.")
}
# if (vintage > 2022) {
# rlang::abort("The most recent PEP release for this geography is 2022.")
# }

raw <- suppressMessages(readr::read_csv("https://www2.census.gov/programs-surveys/popest/datasets/2020-2022/cities/totals/sub-est2022.csv")) %>%
raw <- suppressMessages(readr::read_csv(sprintf("https://www2.census.gov/programs-surveys/popest/datasets/2020-%s/cities/totals/sub-est%s.csv", vintage, vintage))) %>%
dplyr::filter(SUMLEV == "162") %>%
dplyr::mutate(GEOID = paste0(STATE, PLACE),
NAME = paste0(NAME, ", ", STNAME))
Expand Down
9 changes: 9 additions & 0 deletions man/tidycensus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 52fc427

Please sign in to comment.