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

Add getCensusByState function #79

Closed q-w-a closed 2 years ago

q-w-a commented 2 years ago

This pull request contains an idea for an additional function for easily gathering data for multiple states. The proposed function, getCensusByState, is a function where you can supply a vector of states and then retrieve data for each of them, with error handling to take care of the case where a state lacks data or there is some other error. It relies mostly on getCensus and simply automates the process for data retrieval from multiple states. Several examples are included to see how it works.

hrecht commented 2 years ago

Hi @q-w-a, thanks for the interest but this function is out of scope for this package. Data by state exists for some APIs but not all of them - this wouldn't work universally across the Census APIs. Or someone could want to iterate by county, or year etc. An example of this type of iteration (without error handling, good addition!) is in the docs at https://www.hrecht.com/censusapi/articles/getting-started.html#advanced-geographies

You're welcome to of course use your wrapper function in your own scripts. You might be interested in the tidycensus package, which is focused on the ACS and a few other key datasets and includes helper functions that aren't in this package's scope.