Obtaining Census Tract Data in All States using TidyCensus and purr

I was pleasantly surprised how quick purr is to use with TidyCensus to get data for all Census Tracts in America. This code is based on Matt Herman’s example, but I used R’s built in state.abb to get a list of all states. To only the CONUS Census Tracts, you could use state.abb %>% setdiff(c('AK','HI')), which uses R’s built in setdiff to remove AK and HI from the list of states pulled.

acs <- map_dfr(
  state.abb,
  ~get_acs("tract", survey='acs5', var='B01001_001', state=., cache_table = T,
               geometry = T,
               year = 2021)
  )

Leave a Reply

Your email address will not be published. Required fields are marked *