Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect output = "raw" in oa_fetch() when result is returned early #293

Merged
merged 1 commit into from
Oct 23, 2024

Conversation

yjunechoe
Copy link
Collaborator

In oa_fetch(), there's a clause to return res (the single initial query we do at the start to compute on metadata for stuff like # of pages to expect) early when the meta field is empty (i.e., simple "direct" queries):

openalexR/R/oa_fetch.R

Lines 340 to 347 in 42f4d16

if (!is.null(res$meta)) {
## return only item counting
if (count_only) {
return(res$meta)
}
} else {
return(res)
}

At this point of early return, res is always the parsed json, so it was not respecting output = "raw" in cases like oa_fetch(identifier = "W4396214724", output = "raw") which triggers that early return.

The PR makes it so that this initial res can stay either parsed or unparsed, so that it can be returned unparsed if user specifies output = "raw". Since we do need the parsed metadata info, that's now tracked in res_meta. The roundabout way of doing this in the code is to ensure that we only request once and parse as needed.

@yjunechoe yjunechoe marked this pull request as ready for review October 22, 2024 14:08
Copy link
Collaborator

@trangdata trangdata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you June! 🎉

@yjunechoe yjunechoe merged commit 00e56bf into main Oct 23, 2024
7 checks passed
@yjunechoe yjunechoe deleted the output-raw-bugfix branch October 23, 2024 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants