key <- keyring::key_get("my_personal_openalex_key") # or Sys.getenv(...)What a collection is
An OpenAlex collection is a set of IDs (works, authors, sources, …) saved on OpenAlex’s servers under your account. Once it exists, you can:
- filter by it in any later query:
pro_query(collection = "col_...", options = list(corpus = "all")). Other filters still apply, so you can ask for the open-access members, or for those published after a date. Withoutcorpus = "all"only the core works of a works collection are returned (see Core and expansion works). - combine it with other collections through OQL, using AND, OR and NOT (see Combining collections below).
- share it by link (
access = "shared_by_link", see Sharing), and reuse it later without running the original query again.
pro_collection() turns a query from pro_query() into a collection. OpenAlex runs the query on its own servers (an import), and pro_collection() waits for the import and then downloads what select asks for. With the default, that is only the member IDs.
API key
Collections need a personal OpenAlex API key. Organisation keys and some older keys are refused with HTTP 401 on every collection call, even when they work for queries. pro_collection() then stops with a message saying so. Pass the personal key as api_key:
Creating a collection
library(openalexPro)
q <- pro_query(search = "coral bleaching", publication_year = 2024)
f <- pro_collection(
q,
name = "coral bleaching 2024",
project_folder = "proj",
api_key = key
)The progress shows each step:
✔ [coral bleaching 2024] validating query
✔ [coral bleaching 2024] creating collection
✔ [coral bleaching 2024] importing query
✔ [coral bleaching 2024] downloading member IDs
✔ [coral bleaching 2024] converting IDs to parquet
What happens, step by step:
- The query is checked first with OpenAlex’s free
/querytranslation, so an invalid query stops before anything is created. Queries withgroup_byorsamplecannot be imported and stop here too. - The collection is created under
name. A name can be up to 100 characters and must be unique in your account. - OpenAlex imports the query, and the progress bar follows it.
- The member IDs are downloaded as CSV and converted to parquet.
pro_collection() returns the path of the collection folder.
The collection folder
Each query gets its own folder, <project_folder>/<name>.collection/:
proj/coral bleaching 2024.collection/
├── _collection.json query, collection ID, members, imports, credits, select
├── _query_oql.txt the query in readable OQL
├── _query_oql.html
├── members/parquet/members.parquet id, added_at
└── records/ only when select asks for more than "id" (pro_fetch layout)
_collection.json records the same query information as pro_fetch() does (URL, OQL, OQO, record count, times and package version). It adds the collection itself:
Read the member IDs as you would any parquet dataset:
ids <- arrow::read_parquet(file.path(f, "members/parquet/members.parquet"))What to download: select
select |
Downloaded |
|---|---|
"id" (default) |
the member IDs only (free) |
NULL |
nothing: only the collection and _collection.json
|
c("id", "title", "doi") |
member IDs, and records with these fields in records/
|
"all" |
member IDs, and full records in records/
|
Records are fetched with pro_fetch(pro_query(collection = id, select = ..., options = list(corpus = "all"))), so expansion works are included (for a list of queries with name, they come from the queries themselves). Arguments in ... (e.g. workers, compact_parquet) are passed on to pro_fetch().
Running it again
Run pro_collection() again with the same project_folder and name, and it compares the query with the one in _collection.json:
-
Same query. The collection is kept, with the same ID. If an import is still running (e.g. after an interruption),
pro_collection()waits for it. The local downloads are then made to matchselect:- removed fields are dropped from the local records, with no requests;
- added fields re-download the records. Credits are charged per request, not per field, so fetching only the new fields would cost the same;
-
select = NULLdeletes the local downloads and keeps the collection.
-
refresh = TRUE, same or changed query. The collection keeps its ID, and its members are made to match the query now. The query’s IDs are fetched withpro_fetch()(select = "id", the same credits as an import), new IDs are added and members that no longer match are removed. Adding (10,000 per request) and removing (100 per request) are free. Everything is then downloaded again. An import could only add, so it is not used here. -
Changed query without
refresh. The old collection is deleted, and a new one is created under the same name. It gets a new ID.
So with refresh = TRUE the ID always stays, and links and saved searches keep working. A new collection is created only when the old one is gone on OpenAlex or holds another entity.
# add titles and DOIs (re-downloads the records)
pro_collection(q, name = "coral bleaching 2024", project_folder = "proj",
api_key = key, select = c("id", "title", "doi"))
# drop the DOIs again (local only, no requests)
pro_collection(q, name = "coral bleaching 2024", project_folder = "proj",
api_key = key, select = c("id", "title"))When the local folder is gone
A collection with the same name that already exists in your account but is not recorded in project_folder is never deleted. Without refresh, pro_collection() stops. With refresh = TRUE, it takes that collection over: the ID stays (so links and saved searches keep working), its members are synced to the query as described above, and the folder is written again.
# a new machine, or the project folder was deleted
pro_collection(q, name = "coral bleaching 2024", project_folder = "proj",
api_key = key, refresh = TRUE)The name is matched ignoring case, as OpenAlex does, and the collection must hold the same entity (works, authors, …).
Several queries
Without name, a named list of queries gives one collection per element, named after it. Nested names are joined with _:
Long ID and DOI lists: several queries in one collection
OpenAlex imports a query of at most 20,000 characters of OQL, which is about 600 to 800 DOIs. pro_collection() checks this before it creates anything, and stops for a single query that is too long.
To put a longer list into one collection, split it into chunks with pro_query() and pass the list of chunks with name. With a name, a list is not one collection per element but one collection. Its queries are not imported. Instead, pro_collection() fetches them with pro_fetch() (only the id field, in parallel with workers) and adds the IDs to the collection, 10,000 per request (free):
q <- pro_query(doi = dois, chunk_limit = 200) # chunk_1, chunk_2, ...
pro_collection(q, name = "my dois", project_folder = "proj", api_key = key,
workers = 8)✔ [my dois] checking 15 queries
✔ [my dois] creating collection
✔ [my dois] fetching IDs
✔ [my dois] adding members
✔ [my dois] downloading member IDs
✔ [my dois] converting IDs to parquet
-
Speed and cost. Measured in November 2026 with 3,000 DOIs, the same credits (18) either way:
Route Time one import per 600 DOIs 45 to 55 s pro_fetch()withworkers = 1, then adding the IDs44 s pro_fetch()withworkers = 8, then adding the IDs8.5 s Imports run one at a time per collection, and each holds only a few hundred DOIs, so their fixed cost dominates.
pro_fetch()runs the queries in parallel; adding 3,000 IDs took under a second. Records. Fields in
selectbeyond"id"are fetched in the same pass, from the queries themselves, intorecords/. They therefore also work for collections above the 300,000-member filter limit.Interruptions. Running
pro_collection()again resumes the fetch (pro_fetch(resume = TRUE)) and syncs the members again: IDs already in the collection are left alone.Changes. A changed chunk counts as a changed query. Without
refresh, the collection is re-created (new ID). Withrefresh = TRUE, it is kept: everything is fetched again and the members are synced (new IDs added, those no longer found removed; the ID stays).On disk. The queries are in
_parts.parquet(name and URL of each chunk), not in_collection.json, which stays small however long the list is. Re-runs compare the queries locally, without requests.
Using a collection in queries
Core and expansion works
A collection holds all its members: the members CSV, member_count and members/parquet/members.parquet include expansion works (DataCite, Zenodo and repository records) as well as core works. A filter by a works collection, however, follows the usual default of /works and returns only the core works. Add options = list(corpus = "all") (OQL: works (all corpora) where ...) to get every member.
Measured on a collection of 565 Zenodo records (November 2026): the members CSV and corpus = "all" gave 565, the filter alone 132.
Whether expansion works get into a collection depends on the query that fills it: pro_query(doi = dois, options = list(corpus = "all")) finds them, the same query without corpus only the core works.
A collection of one entity type can also filter a related field: a source collection works with primary_location.source.id, an author collection with authorships.author.id. See the OpenAlex documentation.
Combining collections
A classic query URL accepts only one collection filter. To combine collections, use OQL, where and, or and not work between collections. (all corpora) includes the expansion works:
a <- "col_..."; b <- "col_..."
# in both
pro_query(oql = sprintf(
"works (all corpora) where work is in the collection (%s) and work is in the collection (%s)", a, b))
# in either
pro_query(oql = sprintf(
"works (all corpora) where work is in the collection (%s) or work is in the collection (%s)", a, b))
# in a but not in b
pro_query(oql = sprintf(
"works (all corpora) where work is in the collection (%s) and work is not in the collection (%s)", a, b))One request can use up to 5 collections, with up to 300,000 members combined. The AND and OR results were checked against the intersection and union of the member IDs.
Sharing
A new collection is private: only you can see it and filter by it. Set access to change that; NULL (the default) leaves it as it is.
pro_collection(q, name = "coral bleaching 2024", project_folder = "proj",
api_key = key, access = "shared_by_link")access |
Who can view it and filter by it |
|---|---|
"private" |
only you |
"shared_by_link" |
anyone with its link or ID, logged in or not; it is not listed or searchable |
"public" |
anyone, and listed. Only OpenAlex can set this for now: it is refused (HTTP 403) |
"private" unshares it at once, for every link and saved search that uses it. A collection that is re-created (changed query without refresh) gets a new ID, so links to the old one stop working. Use refresh = TRUE to keep the ID when the query changes.
Costs, time and limits
- Free: creating, reading and deleting collections, and downloading the member IDs.
-
Import: costs the same credits as paging through the results yourself, i.e. one list request per 200 results. It runs at about 200 results per second (measured November 2026): about 75 seconds for 15,000 works, and over an hour for the maximum of 1,000,000 members. Interrupting
pro_collection()does not stop the import on OpenAlex; running it again waits for the import to finish. -
Records: downloaded like any other query (
pro_fetch()). -
Limits:
- 1,000,000 members per collection, and 500 collections per account.
- At most 20,000 characters of OQL per import. Longer ID or DOI lists go into one collection in chunks (see Long ID and DOI lists).
- A collection with more than 300,000 members (100,000 for authors) cannot be used as a filter. Its member IDs can still be downloaded, but its records cannot (
selectbeyond"id").