Search code examples
rcensus

error: unknown/unsupported geography heirarchy, when querying Census tracts


I'm following rcensusapi's guide on retrieving data for retrieving Census tract-level data. Here's my code.

getCensus(
  name = "acs/acs5/cprofile",
  vintage = 2018,
  key = Sys.getenv("CENSUS_API"),
  vars = c("NAME","CP03_2014_2018_062E"),
  region = "tract:*",
  regionin = "state:12+county:033"
)

But when I run this code I get this error.

 Error in apiCheck(req) : 
  The Census Bureau returned the following error message:
 error: unknown/unsupported geography heirarchy 

Solution

  • This similar query seemed to work to give a county-wide number.

    getCensus(
      name = "acs/acs5/cprofile",
      vintage = 2018,
      key = Sys.getenv("CENSUS_API"),
      vars = c("NAME","CP03_2014_2018_062E"),
      region = "county:033",
      # region = "county",  # to get all counties in FL
      # region = "congressional district",  # to get all congressional districts in FL
      regionin = "state:12"
    )
    
    #  state county                     NAME CP03_2014_2018_062E
    #1    12    033 Escambia County, Florida               49286
    

    It's also possible to get the values for all Florida counties or congressional districts with the alternate filters above.

    But unfortunately I don't think it's possible to get tract-level detail for this particular query.

    https://api.census.gov/data/2018/acs/acs5/cprofile.html https://api.census.gov/data/2018/acs/acs5/cprofile/examples.html

    Judging by the help at those links, it doesn't look like this survey is available at the tract level. Here are the listed geographical levels for the region parameter from here. (Also, as @ThetaFC noted in the comments, it's possible to query this list directly using listCensusMetadata(name = "acs/acs5/cprofile", vintage = 2018, type = "geography").)

    enter image description here