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: Census surname API query fails #83

Closed sctyner closed 2 years ago

sctyner commented 2 years ago

Describe the bug Surname API Query Fails

To Reproduce

library(censusapi)

md10 <- listCensusMetadata("surname", vintage = 2010)

surnames <- getCensus("surname",  key = Sys.getenv("CENSUS_API_KEY"),
                      vintage = 2010, vars = md10$name)
#> Error in apiParse(req): The Census Bureau returned the following error message:
#>  There was an error while running your query.  We've logged the error and we'll correct it ASAP.  Sorry for the inconvenience. 
#> Your api call was:  https://api.census.gov/data/2010/surname?key=70d269d4e43b5364def30eddea0e5044ccc84848&get=PCTAPI%2CPCTBLACK%2CPCTAIAN%2CCUM_PROP100K%2CPROP100K%2CPCTWHITE%2CRANK%2CCOUNT%2CPCT2PRACE%2CPCTHISPANIC%2CNAME

Created on 2022-05-26 by the reprex package (v2.0.0)

Expected behavior Return the complete Census Surname table for 2010.

R session information:

Additional context I'm just trying to find an easier way to download the surnames table into R without having to download the zip file

hrecht commented 2 years ago

That's an issue on the Census Bureau side - not sure what's going on there. But if you paste the URL from the error message into your browser you'll see the error is coming through the API not from this R package. You'll need to reach out to them for help, I'm not sure what the issue is. Sorry I can't be of more help.

hrecht commented 2 years ago

Hello @sctyner, I've done some digging and it looks like your call works if you limit the response by using the RANK parameter, like so:

surnames <- getCensus(
  "surname", 
  vintage = 2010, 
  ars = md10$name, 
  RANK = "1:100")

I believe the error you were getting is because otherwise it returns too much data for the Census Bureau to handle. This is a common and frustrating error message that isn't very helpful. Were you able to get answers from the Census Bureau? I'd recommend raising this issue, via email census.data@census.gov or in the Census Bureau Slack https://uscensusbureau.slack.com/join/shared_invite/zt-optzh7xs-ApNgf5Yqbo_u2ANXQv67cQ#/shared-invite/email