View source: R/get_rnhgis_shp.R
get_rnhgis_shp | R Documentation |
This function downloads shapefiles from the NHGIS (National Historical Geographic Information System) using the 'ipumsr' package. It caches downloaded shapefiles as RDS files to avoid redundant downloads. It requires an IPUMS API key to be set as an environment variable named 'IPUMS_API_KEY'.
get_rnhgis_shp(
shp,
refresh = FALSE,
save_dir = here::here("data-raw/rnhgis_shp/")
)
shp |
A character vector of length one specifying the name of the shapefile to download. This name corresponds to the shapefile codes used by NHGIS (e.g., "us_state_2020_tl2020"). See the 'ipumsr' documentation for how to find these codes. |
refresh |
Logical. If 'TRUE', forces a refresh of the cached; if 'FALSE' (default), uses the cached data. |
save_dir |
The directory where the downloaded and processed shapefiles will be saved as RDS files. Defaults to '"data-raw/rnhgis_shp/"' using ‘here::here()'. This directory will be created if it doesn’t exist. |
An 'sf' object containing the downloaded shapefile.
## Not run:
# Download and cache the 2020 US counties shapefile.
states <- get_rnhgis_shp("us_state_2020_tl2020")
# Subsequent calls with the same 'shp' argument will load the cached
# shapefile.
states_cached <- get_rnhgis_shp("counties")
identical(states, states_cached) # TRUE
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.