read_nhgis | R Documentation |
Reads a dataset downloaded from the NHGIS extract system. Relies on csv files (with or without the extra header row).
read_nhgis( data_file, data_layer = NULL, verbose = TRUE, var_attrs = c("val_labels", "var_label", "var_desc") ) read_nhgis_sf( data_file, shape_file, data_layer = NULL, shape_layer = data_layer, shape_encoding = "latin1", verbose = TRUE, var_attrs = c("val_labels", "var_label", "var_desc") ) read_nhgis_sp( data_file, shape_file, data_layer = NULL, shape_layer = data_layer, shape_encoding = "latin1", verbose = TRUE, var_attrs = c("val_labels", "var_label", "var_desc") )
data_file |
Filepath to the data (either the .zip file directly downloaded from the website, the path to the unzipped folder, or the path to the unzipped .csv file directly). |
data_layer |
For .zip extracts with multiple datasets, the name of the
data to load. Accepts a character vector specifying the file name, or
|
verbose |
Logical, indicating whether to print progress information to console. |
var_attrs |
Variable attributes to add from the codebook, defaults to
adding all (val_labels, var_label and var_desc). See
|
shape_file |
Filepath to the shape files (either the .zip file directly downloaded from the website, or the path to the unzipped folder, or the unzipped .shp file directly). |
shape_layer |
(Defaults to using the same value as data_layer) Specification
of which shape files to load using the same semantics as |
shape_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. Defaults to "latin1" for NHGIS. |
read_nhgis
returns a tbl_df
with only the tabular data,
read_nhgis_sf
returns a sf
object with data and the shapes, and
read_nhgis_sp
returns a SpatialPolygonsDataFrame
with data and
shapes.
Other ipums_read:
read_ipums_micro_chunked()
,
read_ipums_micro_yield()
,
read_ipums_micro()
,
read_ipums_sf()
,
read_terra_area()
,
read_terra_micro()
,
read_terra_raster()
csv_file <- ipums_example("nhgis0008_csv.zip") shape_file <- ipums_example("nhgis0008_shape_small.zip") data_only <- read_nhgis(csv_file) # If sf package is availble, can load as sf object if (require(sf)) { sf_data <- read_nhgis_sf(csv_file, shape_file) } # If sp package is available, can load as SpatialPolygonsDataFrame if (require(rgdal) && require(sp)) { sp_data <- read_nhgis_sp(csv_file, shape_file) }
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.