hrecht / censusapi

R package to retrieve U.S. Census data and metadata via API
https://www.hrecht.com/censusapi/
169 stars 30 forks source link

Bug report: #86

Closed sisiraul closed 1 year ago

sisiraul commented 1 year ago

Describe the bug I was trying to pull variables from the either 2016-2020 or 2017-2021 ACS Five Year estimates, and got the following error, but it will work for the 2015-2019 ACS. Error in apiCheck(req) : The Census Bureau returned the following error message: error: unknown/unsupported geography heirarchy

To Reproduce rm(list=ls()) library(censusapi) library(tidyverse) library(openxlsx)

Sys.setenv("CENSUS_KEY"="my key") apis <- listCensusApis() View(apis)

acs_vars<-listCensusMetadata(name="acs/acs5",vintage=2019, type = "variables")

pop_zip<-getCensus(name="acs/acs5",vintage=2019, vars=c("B01001_001E","B01001_006E","B01001_007E","B01001_008E", "B01001_009E","B01001_010E","B01001_011E","B01001_012E", "B01001_030E","B01001_031E","B01001_032E","B01001_033E", "B01001_034E","B01001_035E","B01001_036E"), region="zip code tabulation area:*", regionin="state:09")

pop_zip_20<-getCensus(name="acs/acs5",vintage=2020, vars=c("B01001_001E","B01001_006E","B01001_007E","B01001_008E", "B01001_009E","B01001_010E","B01001_011E","B01001_012E", "B01001_030E","B01001_031E","B01001_032E","B01001_033E", "B01001_034E","B01001_035E","B01001_036E"), region="zip code tabulation area:*", regionin="state:09")

Expected behavior I'm hoping this would work for ACS starting from 2020, so I can pull ZCTA data by state.

R session information: R version 4.2.1 (2022-06-23 ucrt) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale: [1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] tigris_2.0.1 censusapi_0.8.0 openxlsx_4.2.5 forcats_0.5.2 stringr_1.4.1 dplyr_1.0.10
[7] purrr_0.3.4 readr_2.1.3 tidyr_1.2.1 tibble_3.1.8 ggplot2_3.3.6 tidyverse_1.3.2 [13] tidycensus_1.3.2

loaded via a namespace (and not attached): [1] tidyselect_1.1.2 sf_1.0-9 haven_2.5.1 gargle_1.2.1 colorspace_2.0-3
[6] vctrs_0.4.2 generics_0.1.3 utf8_1.2.2 rlang_1.0.6 e1071_1.7-12
[11] pillar_1.8.1 withr_2.5.0 glue_1.6.2 DBI_1.1.3 rappdirs_0.3.3
[16] dbplyr_2.2.1 readxl_1.4.1 modelr_0.1.9 uuid_1.1-0 lifecycle_1.0.2
[21] munsell_0.5.0 gtable_0.3.1 cellranger_1.1.0 zip_2.2.1 rvest_1.0.3
[26] tzdb_0.3.0 curl_4.3.2 class_7.3-20 fansi_1.0.3 broom_1.0.1
[31] Rcpp_1.0.9 KernSmooth_2.23-20 backports_1.4.1 scales_1.2.1 classInt_0.4-8
[36] googlesheets4_1.0.1 jsonlite_1.8.2 fs_1.5.2 hms_1.1.2 stringi_1.7.8
[41] grid_4.2.1 cli_3.4.1 tools_4.2.1 magrittr_2.0.3 proxy_0.4-27
[46] crayon_1.5.2 pkgconfig_2.0.3 ellipsis_0.3.2 xml2_1.3.3 reprex_2.0.2
[51] lubridate_1.8.0 googledrive_2.0.0 assertthat_0.2.1 httr_1.4.4 rstudioapi_0.14
[56] R6_2.5.1 units_0.8-1 compiler_4.2.1

Additional context image

hrecht commented 1 year ago

This is a Census Bureau choice, not coming from behavior of the censusapi package. They do not nest ZCTAs by states for all years. You can get data for all ZCTAs nationally or for individual ones where the state nesting is not available.

Of note, actual postal zip codes can and do cross state lines. (ZCTAs are not the same as postal zip codes but this is important to know.)