ipumsr (version 0.4.5)

read_ipums_sf: Read boundary files from an IPUMS extract

Description

Reads the boundary files from an IPUMS extract into R as simple features (sf) objects or SpatialPolygonsDataFrame (sp) objects.

Usage

read_ipums_sf(
  shape_file,
  shape_layer = NULL,
  vars = NULL,
  encoding = NULL,
  bind_multiple = TRUE,
  add_layer_var = NULL,
  verbose = TRUE
)

read_ipums_sp( shape_file, shape_layer = NULL, vars = NULL, encoding = NULL, bind_multiple = TRUE, add_layer_var = NULL, verbose = TRUE )

Arguments

shape_file

Filepath to one or more .shp files, a .zip file from an IPUMS extract or a path to an unzipped folder.

shape_layer

For .zip extracts with multiple datasets, the name of the shape files to load. Accepts a character vector specifying the file name, or dplyr_select_style conventions. Can load multiple shape files, which will be combined.

vars

Which variables in the shape file's data to keep (NULL the default keeps all)

encoding

The text encoding to use when reading the shape file. Typically the defaults should read the data correctly, but for some extracts you may need to set them manually, but if funny characters appear in your data, you may need to. For microdata projects, the default NULL will look for a .cpg file to determine the encoding and if none is available, it will default to latin1. The NHGIS and the IPUMS Terra functions specify the encoding for those projects (latin1 and UTF-8 respectively).

bind_multiple

If TRUE, will combine multiple shape files found into a single object.

add_layer_var

Whether to add a variable named layer that indicates which shape_layer the data came from. NULL, the default, uses TRUE if more than 1 layer is found, and FALSE otherwise.

verbose

I TRUE, will report progress information

Value

read_ipums_sf returns a sf object and read_ipums_sp returns a SpatialPolygonsDataFrame.

See Also

Other ipums_read: read_ipums_micro_chunked(), read_ipums_micro_yield(), read_ipums_micro(), read_nhgis(), read_terra_area(), read_terra_micro(), read_terra_raster()

Examples

Run this code
# NOT RUN {
shape_file <- ipums_example("nhgis0008_shape_small.zip")
# If sf package is availble, can load as sf object
if (require(sf)) {
  sf_data <- read_ipums_sf(shape_file)
}

# If sp package is available, can load as SpatialPolygonsDataFrame
if (require(sp) && require(rgdal)) {
  sp_data <- read_ipums_sp(shape_file)
}

# }

Run the code above in your browser using DataLab