ropensci / openalexR

Getting bibliographic records from OpenAlex
https://docs.ropensci.org/openalexR/
Other
89 stars 19 forks source link

**Feature Request**: Check return value when request returns an error, e.g. query to long #230

Closed rkrug closed 2 months ago

rkrug commented 2 months ago

Hi

I have very long queries and OpenAlex has a limit of the length of API calls (4096). Assume the following:


# q <- openalexR::oa_query(
#            title_and_abstract.search = compact(paste0("(", params$s_1_tca_corpus, ") AND (", params$s_1_case, ")")),
#            group_by = "publication_year"
 #       )

q <- "https://api.openalex.org/works?filter=title_and_abstract.search%3A%28%28biodiversity%20OR%20marine%20OR%20terrestrial%20OR%20forest%20OR%20woodland%20OR%20grassland%20OR%20savanna%20OR%20shrubland%20OR%20peatland%20OR%20ecosystem%20OR%20lake%20OR%20river%20OR%20sea%20OR%20ocean%20OR%20meadow%20OR%20heathland%20OR%20mires%20OR%20bog%20OR%20tundra%20OR%20biosphere%20OR%20desert%20OR%20mountain%20OR%20%22natural%20resource%22%20OR%20estuary%20OR%20fjord%20OR%20fauna%20OR%20flora%20OR%20soil%20OR%20%22coastal%20waters%22%20OR%20wetland%20OR%20freshwater%20OR%20marshland%20OR%20marches%20OR%20dryland%20OR%20seascape%20OR%20landscape%20OR%20coast%20OR%20%22arable%20land%22%20OR%20%22agricultural%20land%22%20OR%20%22natural%20environment%22%20OR%20%22environmental%20resource%22%20OR%20agroforest%20OR%20%22agro-forest%22%20OR%20plantation%20OR%20%22protected%20areas%22%20OR%20chaparral%20OR%20sustainable%20OR%20environment%20OR%20conservation%20OR%20ecosystem%20OR%20nature%20OR%20planet%20OR%20Earth%20OR%20biosphere%20OR%20ecological%20OR%20%22socio-ecological%22%20OR%20restoration%20OR%20wildlife%20OR%20landscape%20OR%20species%20OR%20bioeconomy%20OR%20%22resource%20system%22%20OR%20%22coupled%20system%22%20OR%20nature%29%20AND%20%28%28%28%28transformation%20OR%20transition%20OR%20transformative%20OR%20%22transformative%20change%22%29%20OR%20%28%28shift%20OR%20change%29%20AND%20%28fundamental%20OR%20deep%20OR%20radical%29%29%29%20AND%20%28socio%20OR%20social%20OR%20politics%20OR%20political%20OR%20governance%20OR%20economic%20OR%20cultural%20OR%20system%20OR%20technological%20OR%20inner%20OR%20personal%20OR%20financial%20OR%20business%29%29%20OR%20%28%28%22transformative%20change%22%20OR%20%22deliberate%20transformation%22%20OR%20%22transformative%20turn%22%20OR%20transition%20OR%20%22social-ecological%20change%22%20OR%20%22deep%20change%22%20OR%20%22fundamental%20alteration%22%20OR%20%22profound%20change%22%20OR%20%22profound%20transformation%22%20OR%20%22radical%20transformation%22%20OR%20%22transformational%20change%22%20OR%20%22complete%20change%22%20OR%20%22complete%20transformation%22%20OR%20%22drastic%20change%22%20OR%20%22in-depth%20transformation%22%20OR%20%22progressive%20change%22%20OR%20%22radical%20alteration%22%20OR%20%22radical%20change%22%20OR%20%22revolutionary%20change%22%20OR%20%22significant%20modification%22%20OR%20%22total%20transformation%22%20OR%20transition%20OR%20pathway%20OR%20power%20OR%20agency%20OR%20scale%20OR%20leverage%20OR%20context%20OR%20process%20OR%20regime%20OR%20shift%20OR%20views%20OR%20value%20OR%20structure%20OR%20institution%20OR%20deliberate%20OR%20structural%20OR%20fundamental%20OR%20system%20OR%20deep%20OR%20radical%20OR%20profound%20OR%20drastic%20OR%20widespread%20OR%20political%20OR%20economical%20OR%20structur%20OR%20complete%20OR%20progressive%20OR%20revolutionary%20OR%20substantial%20OR%20significant%29%20AND%20%28transformation%20OR%20alteration%20OR%20change%20OR%20turn%20OR%20action%20OR%20transition%20OR%20shift%29%29%29%29%20AND%20%28data-driven%20OR%20observational%20OR%20statistical%20OR%20experimental%20OR%20real-world%20OR%20%22evidence-based%22%20OR%20factual%20OR%20quantitative%20OR%20qualitative%20OR%20measure%20OR%20research%20OR%20analysis%20OR%20findings%20OR%20investigation%20OR%20survey%20OR%20fieldwork%20OR%20documented%20OR%20verifiable%20OR%20practical%20OR%20objective%20OR%20%22data-collection%22%20OR%20control%20OR%20%22results-oriented%22%20OR%20methodology%20OR%20variable%20OR%20inference%20OR%20%22empirical-evidence%22%20OR%20comparative%20OR%20replication%20OR%20interpretative%20OR%20behavioural%20OR%20outcome%20OR%20dataset%20OR%20modeling%20OR%20contextual%20OR%20evaluation%20OR%20insight%20OR%20instance%20OR%20case%20OR%20sample%20OR%20%22case%20report%22%20OR%20example%20OR%20%22specific%20study%22%20OR%20%22field%20study%22%20OR%20%22exploratory%20study%22%20OR%20%22diagnostic%20study%22%20OR%20%22investigative%20study%22%20OR%20%22in-depth%20study%22%29&group_by=publication_yearhttps://api.openalex.org/works?filter=title_and_abstract.search%3A%28%28biodiversity%20OR%20marine%20OR%20terrestrial%20OR%20forest%20OR%20woodland%20OR%20grassland%20OR%20savanna%20OR%20shrubland%20OR%20peatland%20OR%20ecosystem%20OR%20lake%20OR%20river%20OR%20sea%20OR%20ocean%20OR%20meadow%20OR%20heathland%20OR%20mires%20OR%20bog%20OR%20tundra%20OR%20biosphere%20OR%20desert%20OR%20mountain%20OR%20%22natural%20resource%22%20OR%20estuary%20OR%20fjord%20OR%20fauna%20OR%20flora%20OR%20soil%20OR%20%22coastal%20waters%22%20OR%20wetland%20OR%20freshwater%20OR%20marshland%20OR%20marches%20OR%20dryland%20OR%20seascape%20OR%20landscape%20OR%20coast%20OR%20%22arable%20land%22%20OR%20%22agricultural%20land%22%20OR%20%22natural%20environment%22%20OR%20%22environmental%20resource%22%20OR%20agroforest%20OR%20%22agro-forest%22%20OR%20plantation%20OR%20%22protected%20areas%22%20OR%20chaparral%20OR%20sustainable%20OR%20environment%20OR%20conservation%20OR%20ecosystem%20OR%20nature%20OR%20planet%20OR%20Earth%20OR%20biosphere%20OR%20ecological%20OR%20%22socio-ecological%22%20OR%20restoration%20OR%20wildlife%20OR%20landscape%20OR%20species%20OR%20bioeconomy%20OR%20%22resource%20system%22%20OR%20%22coupled%20system%22%20OR%20nature%29%20AND%20%28%28%28%28transformation%20OR%20transition%20OR%20transformative%20OR%20%22transformative%20change%22%29%20OR%20%28%28shift%20OR%20change%29%20AND%20%28fundamental%20OR%20deep%20OR%20radical%29%29%29%20AND%20%28socio%20OR%20social%20OR%20politics%20OR%20political%20OR%20governance%20OR%20economic%20OR%20cultural%20OR%20system%20OR%20technological%20OR%20inner%20OR%20personal%20OR%20financial%20OR%20business%29%29%20OR%20%28%28%22transformative%20change%22%20OR%20%22deliberate%20transformation%22%20OR%20%22transformative%20turn%22%20OR%20transition%20OR%20%22social-ecological%20change%22%20OR%20%22deep%20change%22%20OR%20%22fundamental%20alteration%22%20OR%20%22profound%20change%22%20OR%20%22profound%20transformation%22%20OR%20%22radical%20transformation%22%20OR%20%22transformational%20change%22%20OR%20%22complete%20change%22%20OR%20%22complete%20transformation%22%20OR%20%22drastic%20change%22%20OR%20%22in-depth%20transformation%22%20OR%20%22progressive%20change%22%20OR%20%22radical%20alteration%22%20OR%20%22radical%20change%22%20OR%20%22revolutionary%20change%22%20OR%20%22significant%20modification%22%20OR%20%22total%20transformation%22%20OR%20transition%20OR%20pathway%20OR%20power%20OR%20agency%20OR%20scale%20OR%20leverage%20OR%20context%20OR%20process%20OR%20regime%20OR%20shift%20OR%20views%20OR%20value%20OR%20structure%20OR%20institution%20OR%20deliberate%20OR%20structural%20OR%20fundamental%20OR%20system%20OR%20deep%20OR%20radical%20OR%20profound%20OR%20drastic%20OR%20widespread%20OR%20political%20OR%20economical%20OR%20structur%20OR%20complete%20OR%20progressive%20OR%20revolutionary%20OR%20substantial%20OR%20significant%29%20AND%20%28transformation%20OR%20alteration%20OR%20change%20OR%20turn%20OR%20action%20OR%20transition%20OR%20shift%29%29%29%29%20AND%20%28data-driven%20OR%20observational%20OR%20statistical%20OR%20experimental%20OR%20real-world%20OR%20%22evidence-based%22%20OR%20factual%20OR%20quantitative%20OR%20qualitative%20OR%20measure%20OR%20research%20OR%20analysis%20OR%20findings%20OR%20investigation%20OR%20survey%20OR%20fieldwork%20OR%20documented%20OR%20verifiable%20OR%20practical%20OR%20objective%20OR%20%22data-collection%22%20OR%20control%20OR%20%22results-oriented%22%20OR%20methodology%20OR%20variable%20OR%20inference%20OR%20%22empirical-evidence%22%20OR%20comparative%20OR%20replication%20OR%20interpretative%20OR%20behavioural%20OR%20outcome%20OR%20dataset%20OR%20modeling%20OR%20contextual%20OR%20evaluation%20OR%20insight%20OR%20instance%20OR%20case%20OR%20sample%20OR%20%22case%20report%22%20OR%20example%20OR%20%22specific%20study%22%20OR%20%22field%20study%22%20OR%20%22exploratory%20study%22%20OR%20%22diagnostic%20study%22%20OR%20%22investigative%20study%22%20OR%20%22in-depth%20study%22%29&group_by=publication_year"

oa_request(query_url = q, count_only = TRUE)

# Result:
#164 Error: lexical error: invalid char in json text.
#                                        <html>   <head>     <title>Bad 
#                      (right here) ------^

But If I run the request in a browser, I get

Screenshot 2024-04-19 at 09 18 41

which is much more informative and helps me to solve the problem.

Would it be possible, to extract that error message and return it?

Thanks.