Any insights will be appreciated! I’m trying to pull data from table B01001 for the year 2022 for the specified ZIPs.
Here is the code and its failure:
YearRangeEnd <- 2022
TblName <- 'B01001'
# ZIPs we want to report
ZIPs <- c(
'48411', '48420', '48423', '48430',
'48433', '48436', '48437', '48438',
'48439', '48451', '48457', '48458',
'48463', '48473', '48502', '48503',
'48504', '48505', '48506', '48507',
'48509', '48519', '48529', '48532'
)
ZIPData <-
get_acs (
geography = 'ZCTA'
, survey='acs5'
, table = TblName
, year = YearRangeEnd
, state = 26
, ZCTA = ZIPs
, cache_table = FALSE # TRUE
)
print (ZIPData)
And the output:
Getting data from the 2018-2022 5-year ACS
Error in map()
:
ℹ In index: 1.
ℹ With name: 1.
Caused by error:
! Your API call has errors. The API message returned is error: unknown/unsupported geography hierarchy.
Run rlang::last_trace()
to see where the error occurred.
rlang::last_trace()
<error/purrr_error_indexed>
Error inmap()
:
ℹ In index: 1.
ℹ With name: 1.
Caused by error:
! Your API call has errors. The API message returned is error: unknown/unsupported geography hierarchy.
Backtrace:
▆
- ├─tidycensus::get_acs(…)
- │ ├─… %>% …
- │ └─purrr::map(…)
- │ └─purrr:::map_(“list”, .x, .f, …, .progress = .progress)
- │ ├─purrr:::with_indexed_errors(…)
- │ │ └─base::withCallingHandlers(…)
- │ ├─purrr:::call_with_cleanup(…)
- │ └─tidycensus (local) .f(.x[[i]], …)
- │ ├─base::suppressWarnings(…)
- │ │ └─base::withCallingHandlers(…)
- │ └─tidycensus:::load_data_acs(…)
- │ └─base::stop(…)
- ├─base::Reduce(…)
- └─base::.handleSimpleError(…)
- └─purrr (local) h(simpleError(msg, call))
-
└─cli::cli_abort(...)
-
└─rlang::abort(...)
Parallel code that gets data for subdivisions works fine:
TblName <- 'B01001'
YearRangeEnd <- 2023
SubData <- get_acs(
geography="county subdivision", state=26
, county=049
, survey='acs5'
, year = YearRangeEnd
, table = TblName
, cache_table = TRUE
)
print (SubData)
I tried replacing the vector of ZIP codes with a single value, changing ‘ to “, writing the single value as a number rather than a string (tidycensus doc says you can), restarting RStudio, changing parameter values.
Anyone have any insights?
So it seems like zipcodes need to be as numbers. I’ve fixed in the code below. From the code, it seems like you need to use “zcta” in non-capitals. Works for me, hope it does for you!
YearRangeEnd <- 2022
TblName <- 'B01001'
# ZIPs we want to report
ZIPs <- c(
'48411', '48420', '48423', '48430',
'48433', '48436', '48437', '48438',
'48439', '48451', '48457', '48458',
'48463', '48473', '48502', '48503',
'48504', '48505', '48506', '48507',
'48509', '48519', '48529', '48532'
)
# I'm too tired to remove all the ' in the strings above
ZIPs <- as.numeric(as.character(ZIPs))
ZIPData <-
get_acs (
geography = 'zcta'
, survey='acs5'
, table = TblName
, year = YearRangeEnd
, state = 26
, ZCTA = ZIPs
, cache_table = FALSE # TRUE
)
print (ZIPData)
Guillaume is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.