README.md

peeracs

I am currently developing a general repository of multiple functions that includes this function. This will soon be deprecated. See https://github.com/tallishmatt/cmappolicyfuns

peeracs is an R package that wraps around the tidycensus get_acs() function to cleanly obtain time series data for a region of counties, peer MSAs, and the nation. Currently, it provides the function assemble_peer_acs() and a function manual that explains how to employ it.

assemble_peer_acs() repeatedly and somewhat intelligently calls get_acs() to quietly collect 1-year ACS data for a set of counties, a set of peer MSAs, and the country. It collects data for a range of years, and if asked can iterate through racially-specific detailed census tables. It tracks suppressed data, and attempts to replace suppressed 1-year data with data from the 5-year ACS. Finally, it sums or calculates a weighted average for the set of counties. It defaults to CMAP's 7 county region, but this can be overridden for use by other regions.

how to install

This package can be installed directly from github:

install.packages("devtools")
library(devtools)
install_github("CMAP-REPOS/peeracs") # Also use this to fetch an updated version of the package.
library(peeracs)

This package depends on the tidyverse and tidycensus packages. Loading the peeracs library will automatically load tidyverse and tidycensus, as long as they are installed.

After installing peeracs, check the manual file (?assemble_peer_acs). If it appears corrupt, restart R. If in Rstudio, try:

.rs.restartR()

assemble_peer_acs arguments

assemble_peer_acs(table = NULL, variables = NULL, years = 2018,
  peers = NULL, racial = FALSE, race = NULL, try_suppressed = TRUE,
  avg_weight = NULL, state_fips = "17",
  counties = c("031", "043", "089", "093", "097", "111", "197")))
}

How to use

Note that the user must have a valid census API key installed into the R environment. A key can be obtained from http://api.census.gov/data/key_signup.html. The following code needs to be run only once:

census_api_key("your key here", install=TRUE, overwrite=TRUE) 
readRenviron("~/.Renviron") 

The manual file for the primary function (from with in R, ?assemble_peer_acs) has important details about which arguments need to be called.

Examples

# The table B23001 for range of years
data <- assemble_peer_acs("B23001", years = 2014:2017)

# the racially-specific table B23002 for just one year
assemble_peer_acs("B23002", years = 2015, racial=TRUE, try_suppressed = FALSE)

# a selection of variables for a range of years
data <- assemble_peer_acs(variables = c("B23001_001", "B23001_002", "B23001_003"),
                                        years = 2014:2017)

# a selection of variables for a range of years, by race, with a weighted average
data <- assemble_peer_acs(variables = c("B19013_001", "B01001_001"),
                                        years = 2014:2015, racial = TRUE,
                                        avg_weight = "B01001_001")

I'm new to this!

Please feel free to suggest any edits to code for style or efficiency best practices.



CMAP-REPOS/peeracs documentation built on Nov. 20, 2019, 2:31 p.m.