censusapi is a wrapper for the United States Census Bureau’s APIs. As of 2017 over 200 Census API endpoints are available, including Decennial Census, American Community Survey, Poverty Statistics, and Population Estimates APIs. This package is designed to let you get data from all of those APIs using the same main function—
getCensus—and the same syntax for each dataset.
censusapi generally uses the APIs’ original parameter names so that users can easily transition between Census’s documentation and examples and this package. It also includes metadata functions to return data frames of available APIs, variables, and geographies.
To use the Census APIs, sign up for an API key. Then, if you’re on a non-shared computer, add your Census API key to your .Renviron profile and call it CENSUS_KEY.
censusapi will use it by default without any extra work on your part. Within R, run:
# Add key to .Renviron Sys.setenv(CENSUS_KEY=YOURKEYHERE) # Reload .Renviron readRenviron("~/.Renviron") # Check to see that the expected key is output in your R console Sys.getenv("CENSUS_KEY")
In some instances you might not want to put your key in your .Renviron - for example, if you’re on a shared school computer. You can always choose to specify your key within
To get started, load the
The Census APIs have over 200 endpoints, covering dozens of different datasets.
To see a current table of every available endpoint, run
apis <- listCensusApis() View(apis)