Closed rempsyc closed 1 month ago
Unfortunately, currently OpenAlex doesn't allow search for works by journal name. In the openalex documentation you linked to:
journal
Value: the OpenAlex ID for a given source, where the source is type: journal Returns: works where the chosen source ID is the primary_location.source.
So yes, this argument needs to be an OpenAlex ID. Doing it in the two steps you have done is the best way to search in this case. Also, using primary_location.source.id
as a filter is the same as journal
. I prefer primary_location.source.id
to guard against future changes made by OpenAlex.
library(openalexR)
journals <- c("Collabra. Psychology", "Personality & Social Psychology Bulletin")
sources <- oa_fetch(
entity = "sources",
display_name.search = journals
)
sources$display_name
#> [1] "Personality & social psychology bulletin"
#> [2] "Collabra. Psychology"
sources$id
#> [1] "https://openalex.org/S187348256" "https://openalex.org/S4210175756"
works <- oa_fetch(
entity = "works",
# journal = sources$id,
primary_location.source.id = sources$id,
options = list(sample = 10)
)
works$so |> unique() |> head()
#> [1] "Personality & social psychology bulletin"
#> [2] "Collabra. Psychology"
Created on 2024-05-12 with reprex v2.0.2
I see, interesting, thanks! Closing this issue then :)
Adding OpenAlex's reasoning for future reference: https://docs.openalex.org/api-entities/works/search-works#why-cant-i-search-by-name-of-related-entity-author-name-institution-name-etc
Why can't you do this in just one step? Well, if you use the search term, "NYU," you might end up missing the ones that use the full name "New York University," rather than the initials. Sure, you could try to think of all possible variants and search for all of them, but you might miss some, and you risk putting in search terms that let in works that you're not interested in. Figuring out which works are actually associated with the "NYU" you're interested shouldn't be your responsibility—that's our job! We've done that work for you, so all the relevant works should be associated with one unique ID.
I would like to do an openalex query for papers (works) while filtering for a list of specific journals. I can fetch the info for
entity = sources
with no problem:However, I am not able to filter by journal when using
entity = works
.display_name.search
, unlike the original query, here searches for titles of the papers instead of journals. The best I can do is a manual search, but then there is no exact match and I have been unable to specify an exact match.The openalex documentation specifies:
So we can try again with double quotes, but it seems to be ignored:
Even specifying
journal=
doesn’t seem to produce the expected result:I do not find an explicit parameter to specify journal in the documented list of filters: https://docs.ropensci.org/openalexR/articles/Filters.html. The official openalex documentation does document a
journal
argument:But I am not able to make it work:
So it seems like that argument expects an OpenAlex ID. This is a bit troublesome because then the workaround requires two steps: 1 to fetch the correc ID from search, and then one to have the proper search.
Is there a way to do this in one step?
Created on 2024-05-12 with reprex v2.1.0