loadACS: Retrieve census data from the American Community Survey.

Description Usage Arguments Details See Also Examples

View source: R/util-census.R

Description

Download data from the Census API and cache it locally on disk. This is a thin wrapper around the acs.fetch function in the [acs package](https://cran.r-project.org/web/packages/acs/index.html). The results of acs.fetch() are converted from a fancy S4 class to a simple data frame. The geographical designations (zip code, state, census block, etc) are specified in the row names, and if zip code (actually ZCTA) is used for the geography, the numeric value is also available as a column.

Usage

1
2
loadACS(filterErr = T, endyear = 2014, span = 5, geography = NULL,
  acs_vars_to_load = NULL)

Arguments

geography

The geographic aggregations and search terms to use with the acs.fetch interface. This will default to all zip codes.

acs_vars_to_load

A dataframe to specify which variables to load and what to name the resultant columns. The dataframe should have columns "census_var" and "label" as characters. See example below. This will default to the variables specified in data-raw/census/census_vars.txt

filterErr=T

Remove the standard error columns from the results

endyear=2014

Specify which year of data to download. Currently, 2013 & 2014 are available.

span=5

Whether you want the 3-year or the 5-year estimates. See census website for more explanations.

Details

Before using these functions, you will need to set a census API key. You can get one from http://api.census.gov/data/key_signup.html Once you have obtained a key, set it up like so: acs::api.key.install(key='PASTE_YOUR_KEY_HERE') If you are a developer who frequently reinstalls packages, you may want to copy this into your .Rprofile

The path to the cache directory is stored as an R option. You may customize it by creating a .Rprofile file in either your project or home directory. options("visdom.acs.cache"="/new/path/to/cache/dir") getOption("visdom.acs.cache") clear_acs_cache()

The default set of Data Profile variables are specified in raw-data/census/census_vars.txt. If you edit that list, don't forget to re-execute migrateData.R. You can look at what variables are available by going to http://www.census.gov/data/developers/data-sets/acs-5year.2014.html, choosing the appropriate year, searching the page for "ACS Data Profile API Variables", and clicking html. As of November 11, 2016, the API only works reliably for 2013 and 2014.

See Also

DataSource

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
  library(acs)
  # Load data by state
  loadACS(geography = acs::geo.make(state='*'))
  # Load data for 2 zip codes
  loadACS(geography = c(acs::geo.make(zip.code='94709'), acs::geo.make(zip.code='94710')))
  # Load data for all tracts, restricted to California.
  loadACS(geography = acs::geo.make(state='CA', county='*', tract='*'))
  # Unfortunately, Zip codes can't be restricted to a single state like tracts can.
  
  # Selecting different variables
  acs_vars_to_load = data.frame(
       census_var = c("DP02_0015", "DP04_0047"),
       label = c("avg_hh_size", "owner_hh_size"),
       stringsAsFactors = F )
  loadACS(acs_vars_to_load = acs_vars_to_load)

ConvergenceDA/visdom documentation built on May 6, 2019, 12:51 p.m.