Search code examples
rtidycensus

I have an error in Tidycensus: Error: Your API call has errors


I am trying to extract some information on occupation from American Community Survey (ACS). But I am getting an error. How can I fix it?

Error -

Getting data from the 2016-2020 5-year ACS
Loading ACS5 variables for 2020 from table B24010 and caching the dataset for faster future access.
Using FIPS code '06' for state 'CA'
No encoding supplied: defaulting to UTF-8.
Error: Your API call has errors.  The API message returned is .

Code -

library(tidyverse)
library(tidycensus)

occupation <- get_acs(
    geography = "tract", 
    table = "B24010",
    # summary_var = "B24010_001",
    state = "CA", 
    year = 2020,
    geometry = TRUE,
    cache_table = TRUE)

Solution

  • I think the issue is that the table B24010 is not available via the Census API for that year.

    This error and the cause is discussed in a Github issue.

    Get the 2020 variables (5 year):

    library(tidyverse)
    library(tidycensus)
    
    census_vars <- load_variables(2020, "acs5", cache = TRUE)
    

    Do they include B24010? No they don't.

    census_vars %>% 
      filter(str_detect(name, "B24010"))
    
    # A tibble: 0 × 4