Read and write an
ipums_extract object to a JSON
file that contains the extract definition specifications.
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
save_extract_as_json(extract, file, overwrite = FALSE) define_extract_from_json(extract_json)
File path to which to write the JSON-formatted extract definition.
file if it already exists.
Path to a file containing a JSON-formatted extract definition.
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
API version for the request should be stored in the saved JSON file. (If
there is no
"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
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
camelCase. For instance,
"data_tables" would become
"data_format" would become
"dataFormat", and so on. You will also need to change the
"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 appropriate
my_extract <- define_extract_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) #>  TRUE file.remove(extract_json_path) #>  TRUE