Convenience wrapper that downloads records from OpenAlex via
pro_request() and converts them directly to an Apache Parquet
dataset via pro_request_parquet(). No intermediate JSONL
files are written.
Usage
pro_fetch(
query_url,
pages = 10000,
project_folder = NULL,
overwrite = FALSE,
api_key = pro_api_key(),
delete_input = TRUE,
workers = 1,
download_workers = workers,
verbose = FALSE,
progress = TRUE,
enrich = TRUE,
count_only,
error_log = NULL,
resume = FALSE,
via = c("oqo", "url"),
inconsistency_on_resume = c("error", "warning", "ignore", "oldest", "newest"),
compact_parquet = NULL,
hive_names = NULL
)Arguments
- query_url
The URL of the API query or a list of URLs returned from
pro_query().- pages
The maximum number of pages (of 200 records) downloaded per query; for a list, the limit applies to each leaf query. 100000 pages are 20,000,000 records; for more, use the snapshot instead. If
NULL, all pages will be downloaded.- project_folder
Directory where intermediate (
json) and final (parquet) results are stored. If it does not exist, it is created. IfNULL, a temporary directory is created.- overwrite
Logical. If
TRUE, thejsonandparquetsubdirectories are deleted fromproject_folderbefore the pipeline starts. IfFALSE(the default) and any of those subdirectories already exist, the function stops with an error.- api_key
Character string API key or
NULL. Defaults topro_api_key(). IfNULLor"", requests are sent without an API key (subject to OpenAlex's unauthenticated limits).- delete_input
Logical. If
TRUE(the default), thejsonsubfolder is deleted after successful conversion to Parquet.- workers
Number of parallel workers for the conversion to Parquet (CPU and memory bound), and by default also for the download. Default 1.
- download_workers
Number of parallel workers for the download, used when
query_urlis a list. Defaults toworkers. Downloads are limited by the API rather than the machine, so a few (e.g. 2–4) are usually enough, while the conversion can use more.- verbose
Logical indicating whether to show verbose messages.
- progress
Logical indicating whether to show a progress bar. Default
TRUE.- enrich
Logical. When
TRUE(the default) and the inferred schema containsabstract_inverted_index/authorships/publication_year, addabstractandcitationcomputed columns.- count_only
Do not use it here. The function will abort if set to
TRUEand give a warning ifFALSE.- error_log
location of error log of API calls. (default:
NULL(none)).- resume
Logical. When
TRUE, keep existingjsonandparquetsubfolders and complete an interrupted run: only leaf queries that did not finish are downloaded again, and only missing Parquet files are converted. A finished run is returned unchanged.overwriteis ignored. DefaultFALSE.- via
How each query is sent.
"oqo"(default): translated once (free) into an OpenAlex Query Object and sent via POST, with the same results as"url", which sends it as a GET request with the query in the URL, as built bypro_query(). It has no URL length limit, accepts more than 100 values per filter (sopro_query(..., chunk_limit = 200)fetches a DOI or ID list in about one page per chunk), checks the query before any credits are spent, and records the exact query in_query.json. Single records (works/W123) are always fetched via GET.- inconsistency_on_resume
What to do when a query that was resumed in the middle turns out inconsistent, because OpenAlex's data changed between the sessions: records that appear twice (found exactly, by work ID) or missing records (only as a net difference to OpenAlex's current count – a record lost and another added cancel out).
"error"(default) stops; nothing is lost, and a rerun withresume = TRUEand another value applies that choice without downloading again."warning"keeps both copies and warns,"ignore"keeps both silently,"oldest"/"newest"keep the first / last downloaded copy (removing the other from its page file) and warn about missing records.- compact_parquet
NULL(default) keeps one Parquet file per API page. A number, e.g.250000, combines each query's page files into files of up to that many records once every file has converted – much faster to read. Seepro_compact_parquet().- hive_names
Character vector of Hive partition keys, one per nesting level of a list of queries:
c("topic", "year")writestopic=<name>/year=<name>/.NULL(default) usesqueryfor the first level andquery_l2,query_l3, ... below it;NAkeeps the default of that level. A query namedkey=value(e.g."year=2020") supplies its own key, unlesshive_namesnames one for that level. Keys must be unique and made of letters, digits and_. Use the same value when resuming, or the files are converted again.
Details
The function
downloads records from OpenAlex via
pro_request()into a"json"subfolder ofproject_folder, andconverts the JSON files to an Apache Parquet dataset via
pro_request_parquet()into a"parquet"subfolder.
This function assumes count_only == FALSE
See also
pro_request() for the download step,
pro_request_parquet() for the conversion step,
pro_compact_parquet() to compact an existing dataset.
Examples
if (FALSE) { # \dontrun{
# Combine each query's page files into files of up to 250,000 records,
# which are much faster to read
pro_fetch(
pro_query(search = "coral reef", from_publication_date = "2020-01-01"),
project_folder = "coral_reef",
compact_parquet = 250000
)
} # }