Jon Nigrine
Jon Nigrine

Reputation: 1

Getting errors with tidycensus code that ran fine last year

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 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.


Backtrace: ▆

  1. ├─tidycensus::get_acs(...)
  2. │ ├─... %>% ...
  3. │ └─purrr::map(...)
  4. │ └─purrr:::map_("list", .x, .f, ..., .progress = .progress)
  5. │ ├─purrr:::with_indexed_errors(...)
  6. │ │ └─base::withCallingHandlers(...)
  7. │ ├─purrr:::call_with_cleanup(...)
  8. │ └─tidycensus (local) .f(.x[[i]], ...)
  9. │ ├─base::suppressWarnings(...)
  10. │ │ └─base::withCallingHandlers(...)
  11. │ └─tidycensus:::load_data_acs(...)
  12. │ └─base::stop(...)
  13. ├─base::Reduce(...)
  14. └─base::.handleSimpleError(...)
  15. └─purrr (local) h(simpleError(msg, call))
  16. └─cli::cli_abort(...)
    
  17.   └─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?

Upvotes: 0

Views: 35

Answers (1)

Guillaume
Guillaume

Reputation: 21

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)

Upvotes: 0

Related Questions