read_decennial: Read decennial census data

View source: R/read_decennial.R

read_decennialR Documentation

Read decennial census data

Description

This function retrieves data from summary file 1 (with urban/rural update) of decennial censuses. In addition to selected geographic headers and table contents, it also returns total population and coordinates of selected geographic areas, as well as summary levels and geographic components.

Usage

read_decennial(
  year,
  states,
  table_contents = NULL,
  areas = NULL,
  geo_headers = NULL,
  summary_level = NULL,
  geo_comp = "total",
  show_progress = TRUE
)

Arguments

year

year of the decennial census

states

vector of state abbreviations, for example "IN" or c("MA", "RI").

table_contents

selected references of contents in census tables. Users can choose a name for each reference, such as in c("abc = PCT012F139", "fff = P0030008", "rural_p = P0020005"). Try to make names meaningful. To find the references of table contents of interest, search with function search_tablecontents.

areas

For metro area, in the format like "New York metro". For county, city, or town, must use the exact name as those in dict_fips in the format like "kent county, RI", "Boston city, MA", and "Lincoln town, RI". And special examples like "Salt Lake City city, UT" must keep the "city" after "City".

geo_headers

vector of references of selected geographci headers to be included in the return. Search with search_geoheaders

summary_level

select which summary level to keep, default to keep all. It takes strings including "state", "county", "county subdivision", "place", "tract", "block group", and "block" for the most common levels. It also take code for level. Search all codes with search_summarylevels.

geo_comp

select which geographic component to keep, "*" to keep every geo-component, "total" for "00", "urban" for "01", "urbanized area" for "04", "urban cluster" for "28", "rural" for "43". For all other geographic component, use code, which can be found with search_geocomponents. Availability of geocomponent depends on summary level. State level contains all geographic component. County subdivision and higher level have "00", "01", and "43". Census tract and lower level have only "00".

show_progress

show progress of file reading if TRUE. Turn off if FALSE, which is useful in RMarkdown output.

Value

A data.table whose columns include the selected geoheaders and table contents plus SUMLEV, GEOCOMP, and state.

Examples

## Not run: 
# read one table and one area from one state
aaa = read_decennial(
    year = 2010,
    states = "UT",
    table_contents = c("urban = P0020002", "rural = P0020005"),
    geo_headers = "CBSA",
    summary_level = "tract"
)


# read multiple table contents and areas from multiple states
bbb = read_decennial(
    year = 2010,
    states = c("UT", "RI"),
    table_contents = c("urban = P0020002", "rural = P0020005"),
    areas = c(
        "place = ut62360",
        "Providence city, RI",
        "cousub = ri41500",
        "cbsa = 39300"
    ),
    summary_level = "block"
)


# read table contents of all county subdivisions in Providence metro
ccc <- read_decennial(
    year = 2010,
    states = "US",
    table_contents = c("urban = P0020002", "rural = P0020005"),
    geo_headers = "CBSA",
    summary_level = "county subdivision",
    geo_comp = "*"
)

## End(Not run)


GL-Li/totalcensus documentation built on Jan. 30, 2024, 9:07 p.m.