View source: R/api_process_extract.R
download_extract | R Documentation |
Download IPUMS data extract files via the IPUMS API and save them on your computer.
Learn more about the IPUMS API in vignette("ipums-api")
.
download_extract(
extract,
download_dir = getwd(),
overwrite = FALSE,
progress = TRUE,
api_key = Sys.getenv("IPUMS_API_KEY")
)
extract |
One of:
For a list of codes used to refer to each collection, see
|
download_dir |
Path to the directory where the files should be written. Defaults to current working directory. |
overwrite |
If |
progress |
If |
api_key |
API key associated with your user account. Defaults to the
value of the |
For NHGIS extracts, data files and GIS files (shapefiles) will be saved in
separate .zip archives. download_extract()
will return a character vector
including the file paths to all downloaded files.
For microdata extracts, only the file path to the downloaded .xml DDI file will be returned, as it is sufficient for reading the data provided in the associated .dat.gz data file.
The path(s) to the files required to read the data requested in the extract, invisibly.
For NHGIS, paths will be named with either "data"
(for tabular data
files) or "shape"
(for spatial data files) to
indicate the type of data the file contains.
read_ipums_micro()
or read_nhgis()
to read tabular
data from an IPUMS extract.
read_ipums_sf()
to read spatial data from an IPUMS extract.
ipums_list_files()
to list files in an IPUMS extract.
usa_extract <- define_extract_micro(
collection = "usa",
description = "2013-2014 ACS Data",
samples = c("us2013a", "us2014a"),
variables = c("SEX", "AGE", "YEAR")
)
## Not run:
submitted_extract <- submit_extract(usa_extract)
downloadable_extract <- wait_for_extract(submitted_extract)
# For microdata, the path to the DDI .xml codebook file is provided.
usa_xml_file <- download_extract(downloadable_extract)
# Load with a `read_ipums_micro_*()` function
usa_data <- read_ipums_micro(usa_xml_file)
# You can also download previous extracts with their collection and number:
nhgis_files <- download_extract("nhgis:1")
# NHGIS extracts return a path to both the tabular and spatial data files,
# as applicable.
nhgis_data <- read_nhgis(data = nhgis_files["data"])
# Load NHGIS spatial data
nhgis_geog <- read_ipums_sf(data = nhgis_files["shape"])
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.