View source: R/api_define_extract.R
save_extract_as_json | R Documentation |
Write an ipums_extract
object to a JSON file, or
read an extract definition from such a file.
Use these functions to store a copy of an extract definition outside of your R environment and/or share an extract definition with another registered IPUMS user.
Learn more about the IPUMS API in vignette("ipums-api")
.
save_extract_as_json(extract, file, overwrite = FALSE)
define_extract_from_json(extract_json)
extract |
An |
file |
File path to which to write the JSON-formatted extract definition. |
overwrite |
If |
extract_json |
Path to a file containing a JSON-formatted extract definition. |
An ipums_extract
object.
As of v0.6.0, ipumsr only supports IPUMS API version 2. If you have stored
an extract definition made using version beta or version 1 of the IPUMS
API, you will not be able to load it using define_extract_from_json()
. The
API version for the request should be stored in the saved JSON file. (If
there is no "api_version"
or "version"
field in the JSON file, the
request was likely made under version beta or version 1.)
If the extract definition was originally made under your user account and
you know its corresponding extract number, use get_extract_info()
to obtain
a definition compliant with IPUMS API version 2. You can then save this
definition to JSON with save_extract_as_json()
.
Otherwise, you will need to update the JSON file to be compliant with
IPUMS API version 2. In general, this should only require renaming
all JSON fields written in snake_case
to camelCase
. For instance,
"data_tables"
would become "dataTables"
, "data_format"
would become
"dataFormat"
, and so on. You will also need to change the "api_version"
field to "version"
and set it equal to 2
. If you are unable to create
a valid extract by modifying the file, you may have to recreate the
definition manually using the define_extract_micro()
or
define_extract_nhgis()
.
See the IPUMS developer documentation for more details on API versioning and breaking changes introduced in version 2.
define_extract_micro()
or define_extract_nhgis()
to define an
extract request manually
get_extract_info()
to obtain a past extract to save.
submit_extract()
to submit an extract request for processing.
add_to_extract()
and remove_from_extract()
to
revise an extract definition.
my_extract <- define_extract_micro(
collection = "usa",
description = "2013-2014 ACS Data",
samples = c("us2013a", "us2014a"),
variables = c("SEX", "AGE", "YEAR")
)
extract_json_path <- file.path(tempdir(), "usa_extract.json")
save_extract_as_json(my_extract, file = extract_json_path)
copy_of_my_extract <- define_extract_from_json(extract_json_path)
identical(my_extract, copy_of_my_extract)
file.remove(extract_json_path)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.