| Title: | Snowball searches for OpenAlex using the openalexPro pipeline |
|---|---|
| Description: | Perform snowball searches on the OpenAlex citation graph using openalexPro's on-disk processing pipeline and store results in Parquet. |
| Authors: | Rainer M Krug [aut, cre] (ORCID: <https://orcid.org/0000-0002-7490-0066>) |
| Maintainer: | Rainer M Krug <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.15.6 |
| Built: | 2026-11-24 21:51:16 UTC |
| Source: | https://github.com/openalexPro/openalexSnowball |
A function to perform a snowball search and convert the result to a tibble/data frame.
pro_snowball( identifier = NULL, doi = NULL, snapshot = NULL, max_results = 100000L, workers = 1L, chunk_limit = NULL, select = NULL, endpoint = "https://api.openalex.org", duckdb_config = NULL, resume = FALSE, keep_intermediates = FALSE, output = tempfile(fileext = ".snowball"), verbose = FALSE )pro_snowball( identifier = NULL, doi = NULL, snapshot = NULL, max_results = 100000L, workers = 1L, chunk_limit = NULL, select = NULL, endpoint = "https://api.openalex.org", duckdb_config = NULL, resume = FALSE, keep_intermediates = FALSE, output = tempfile(fileext = ".snowball"), verbose = FALSE )
identifier |
Character vector of openalex identifiers. |
doi |
Character vector of dois. |
snapshot |
Path to a local OpenAlex snapshot (either a root directory
containing Snapshot mode requires the indexes built by
The output construct is identical – |
max_results |
Snapshot mode only: refuse to expand a keypaper with more citing works than this. A heavily cited work can have hundreds of thousands of citers, and extracting records for all of them would read most of the corpus. |
workers |
Number of parallel workers. Default Both paths gain from raising it, but in different places. API mode
parallelises across the chunked query URLs – Raising it buys little for a snowball over a handful of keypapers, where fixed costs dominate; it matters at hundreds or thousands. Be aware that in API mode more workers means more concurrent requests, so keep it within the OpenAlex rate limit for your key. |
chunk_limit |
API mode only: how many keypaper ids go into one filter
URL.
At |
select |
Snapshot mode only: which node columns to keep. This is the single biggest cost in snapshot mode. Works records carry ~51
columns of deeply nested structs, and extracting all of them dominates the
run: measured over 427 nodes, 177.8 s for all columns against 16.7 s for
three – a 10.6x difference, or 20.3x combined with
|
endpoint |
API mode only: base URL of the OpenAlex API. Defaults to
Point this at a self-hosted OpenAlex instance (OurResearch publish the
production stack as Trailing slashes are stripped. Ignored in snapshot mode, where no request is made. |
duckdb_config |
DuckDB settings for the two connections this function
opens. The defaults matter at scale. DuckDB's own are a options(openalexSnowball.duckdb_config = list(concurrency = 4)) |
resume |
Continue an interrupted run in an existing Stages already completed are skipped, and within the fetch stage only
the query chunks that did not finish are re-requested. Resuming with
different keypapers, Note that the default |
keep_intermediates |
Keep the |
output |
parquet dataset; default: temporary directory. |
verbose |
Logical indicating whether to show a verbose information.
Defaults to |
The folder of the results containing multiple subfolders.
In snapshot mode almost all the time goes on retrieving the node records, not on finding which works the snowball contains. Measured over 100 random keypapers against the full corpus:
| phase | time | share |
get_citing() -- citation index |
7.3 s | 7% |
get_cited() -- referenced_works |
1.2 s | 1% |
| record retrieval | 95.5 s | 92% |
The indexes are not the bottleneck, and neither is the id-to-location lookup. The cost is the scattered read that follows it. Those 100 keypapers produced 3,121 nodes living in 1,222 of the corpus's 2,127 parquet files – 57% of the corpus, at an average of 2.6 wanted rows per file opened. Each file still costs an open, a footer parse and a row-group decompression.
Two things follow.
Name the columns you need. select= cannot reduce how many files are
opened, but it cuts the bytes decompressed inside each one, which is where
its large speed-up comes from.
Pass all keypapers to one call rather than looping. The file set saturates: it cannot exceed 2,127 however many keypapers you give, and 100 keypapers already reach 1,222 of them. Cost is therefore strongly concave in the number of keypapers – ten times the keypapers costs roughly twice the time, not ten times. A loop of 200 separate calls re-pays the scattered-read cost 200 times over largely the same files:
# avoid -- pays the corpus-wide scattered read 200 times for (grp in groups) pro_snowball(identifier = grp, snapshot = snap, ...) # prefer -- one scattered read, one deduplicated result pro_snowball(identifier = unlist(groups), snapshot = snap, ...)
The caveat is that pooling produces one snowball. oa_input,
relation, is_keypaper / is_citing / is_cited and edge_type are all
defined relative to the keypaper set of that call, so a pooled run cannot
tell you which of your original groups a given node came from. If you need
the groups kept apart, pool anyway and re-derive membership afterwards by
joining the edges back to each group's keypaper ids – that is far cheaper
than re-reading the corpus per group.
This applies only to snapshot=. API mode is network-bound and scales
roughly linearly in keypapers; see workers and chunk_limit there.
id is a key in nodes/: every OpenAlex work appears exactly once,
whichever backend produced it. A work can nonetheless hold more than one
role in the same snowball – a keypaper that cites another keypaper is both
keypaper and citing – so the roles are recorded as three independent
flags:
is_keypaper – the work is one of the supplied keypapers.
is_citing – the work cites at least one keypaper.
is_cited – the work is cited by at least one keypaper.
Any combination can be TRUE, and at least one always is. The flags
describe a work's role in this snowball, not a property of the work.
sb <- read_snowball(out, return_data = TRUE) subset(sb$nodes, is_citing & is_cited) # works in both directions subset(sb$nodes, !is_keypaper) # the snowballed neighbourhood
relation is kept alongside them and is the hive partition key of
nodes/, but it records only the highest-precedence role (keypaper >
citing > cited) and is therefore lossy: a work that is both citing and
cited reports relation = "citing", so relation == "cited" does not
find every cited work. Filter on the booleans; use relation only for
partition pruning.
Both backends behave identically here – the flags are computed at node assembly, after the API or snapshot rows have been collected.
A function to extract the edges from a parquet database containing the nodes
pro_snowball_extract_edges( nodes = NULL, output = tempfile(fileext = ".snowball"), duckdb_config = NULL, verbose = FALSE )pro_snowball_extract_edges( nodes = NULL, output = tempfile(fileext = ".snowball"), duckdb_config = NULL, verbose = FALSE )
nodes |
Path to the nodes parquet dataset |
output |
output folder, in which the parquet database containing the
edges called |
duckdb_config |
DuckDB settings for the edge-extraction connection.
See |
verbose |
Logical indicating whether to show a verbose information.
Defaults to |
A list containing 2 elements:
nodes: dataframe with publication records.
The last column oa_input indicates whether the work was one of the input
identifier(s).
edges: publication link dataframe of 2 columns from, to
such that a row A, B means A -> B means A cites B. In bibliometrics, the
"citation action" comes from A to B.
## Not run: snowball_docs <- pro_snowball( identifier = c("W2741809807", "W2755950973"), citing_params = list(from_publication_date = "2022-01-01"), cited_by_params = list(), verbose = TRUE ) # Identical to above, but searches using paper DOIs snowball_docs_doi <- oa_snowball( doi = c("10.1016/j.joi.2017.08.007", "10.7717/peerj.4375"), citing_params = list(from_publication_date = "2022-01-01"), cited_by_params = list(), verbose = TRUE ) ## End(Not run)## Not run: snowball_docs <- pro_snowball( identifier = c("W2741809807", "W2755950973"), citing_params = list(from_publication_date = "2022-01-01"), cited_by_params = list(), verbose = TRUE ) # Identical to above, but searches using paper DOIs snowball_docs_doi <- oa_snowball( doi = c("10.1016/j.joi.2017.08.007", "10.7717/peerj.4375"), citing_params = list(from_publication_date = "2022-01-01"), cited_by_params = list(), verbose = TRUE ) ## End(Not run)
A function to get the nodes for a snowball search
pro_snowball_get_nodes( identifier = NULL, doi = NULL, limit = NULL, snapshot = NULL, max_results = 100000L, workers = 1L, chunk_limit = NULL, select = NULL, endpoint = "https://api.openalex.org", duckdb_config = NULL, resume = FALSE, cleanup = TRUE, prepared = FALSE, output = tempfile(fileext = ".snowball"), verbose = FALSE )pro_snowball_get_nodes( identifier = NULL, doi = NULL, limit = NULL, snapshot = NULL, max_results = 100000L, workers = 1L, chunk_limit = NULL, select = NULL, endpoint = "https://api.openalex.org", duckdb_config = NULL, resume = FALSE, cleanup = TRUE, prepared = FALSE, output = tempfile(fileext = ".snowball"), verbose = FALSE )
identifier |
Character vector of openalex identifiers. |
doi |
Character vector of dois. |
limit |
If |
snapshot |
Path to a local OpenAlex snapshot (either a root directory
containing |
max_results |
Snapshot mode only: refuse to expand a keypaper with more
citing works than this. See |
workers |
Number of parallel workers. Default |
chunk_limit |
API mode only: ids per filter URL. |
select |
Snapshot mode only: node columns to keep. See |
endpoint |
API mode only: base URL of the OpenAlex API. See
|
duckdb_config |
DuckDB settings for the assembly connection. See
|
resume |
Keep an existing |
cleanup |
Remove the intermediate |
prepared |
Internal. |
output |
parquet dataset; default: temporary directory. |
verbose |
Logical indicating whether to show a verbose information.
Defaults to |
Path to the nodes parquet dataset
This function reads a snowball from Apache Parquet format and returns a list
containing nodes and edges, which can be either Arrow Datasets or tibbles.
read_snowball( snowball = NULL, edge_type = c("core", "extended", "outside"), return_data = FALSE, shorten_ids = FALSE, meta = FALSE )read_snowball( snowball = NULL, edge_type = c("core", "extended", "outside"), return_data = FALSE, shorten_ids = FALSE, meta = FALSE )
snowball |
The directory of the Parquet files as poppulater by
|
edge_type |
type of the returned edges. Possible values are:
|
return_data |
Logical indicating whether to return an |
shorten_ids |
If |
meta |
Also return provenance as a third list element |
A list containing two elements: nodes and edges, which are either
ArrowObject representing the corpus or tibbles containing the data
(plus meta when meta = TRUE).
nodes has one row per OpenAlex work – id is a key – and carries the
role columns described below.
A work can hold more than one role in the same snowball: a keypaper that
cites another keypaper is both a keypaper and a citing work, and a work can
both cite one keypaper and be cited by another. Because id is a key, those
roles cannot each get their own row, so they are three independent flags on
the single row:
is_keypaper – the work is one of the supplied keypapers.
is_citing – the work cites at least one keypaper.
is_cited – the work is cited by at least one keypaper.
Any combination can be TRUE, and at least one always is. Filter on these:
sb <- read_snowball(path, return_data = TRUE) subset(sb$nodes, is_citing) # everything citing a keypaper subset(sb$nodes, is_citing & is_cited) # works in both directions subset(sb$nodes, !is_keypaper) # the snowballed neighbourhood
relation is also present and is the hive partition key of nodes/, but it
records only the highest-precedence role (keypaper > citing >
cited). A work that is both citing and cited reports
relation = "citing", so relation == "cited" does not find every
cited work – is_cited does. Use relation for partition pruning and the
booleans for filtering.
The flags describe a work's role in this snowball, not a property of the
work: the same paper can be is_cited in one snowball and is_citing in
another.
pro_snowball() opens DuckDB twice – once to assemble nodes/, once to
extract edges/. This builds the settings applied to both.
snowball_duckdb_config( memory_limit = "auto", temp_directory = "auto", threads = "auto", preserve_insertion_order = FALSE, partitioned_write_max_open_files = NULL, max_temp_directory_size = NULL, concurrency = 1L )snowball_duckdb_config( memory_limit = "auto", temp_directory = "auto", threads = "auto", preserve_insertion_order = FALSE, partitioned_write_max_open_files = NULL, max_temp_directory_size = NULL, concurrency = 1L )
memory_limit |
DuckDB |
temp_directory |
Root for DuckDB's spill files. |
threads |
|
preserve_insertion_order |
Defaults to |
partitioned_write_max_open_files |
|
max_temp_directory_size |
|
concurrency |
How many |
Settings resolve per field, not per object: an explicit argument field
beats the same field of getOption("openalexSnowball.duckdb_config"),
which beats the package default. So setting one field in the option does
not silently discard the safe defaults for the others, and passing
duckdb_config = list(threads = 2) at a call site does not discard a
session-wide memory budget.
Note that memory_limit is a fairness and blast-radius control rather than
a correctness one: lowering it does not make a query fit, it makes a
failure arrive sooner and stops one run from starving the others.
A list of class openalexSnowball_duckdb_config.
snowball_duckdb_config(memory_limit = "8GB", concurrency = 4)snowball_duckdb_config(memory_limit = "8GB", concurrency = 4)