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

xml_find_num: should handle missing node; #356

Closed
discoleo opened this issue Feb 9, 2022 · 3 comments
Closed

xml_find_num: should handle missing node; #356

discoleo opened this issue Feb 9, 2022 · 3 comments
Labels
reprex needs a minimal reproducible example

Comments

@discoleo
Copy link

discoleo commented Feb 9, 2022

Example:
xml_find_num(xml, "/some/path/that/does/not/exist")

Should check if it is a request for NUMBER:
if (result_ == NULL) {
// should first check if the request is for NUMBER and return a NA;
SEXP ret = PROTECT(Rf_allocVector(VECSXP, 0));
Rf_setAttrib(ret, R_ClassSymbol, Rf_mkString("xml_missing"));
UNPROTECT(1);
return ret;
}

For missing nodes:

  • either return NA;
  • or add argument to function: xml_find_num(xml, xpath, defaultVal=NA);
@hadley
Copy link
Member

hadley commented Feb 28, 2022

Can you please provide a minimal reprex (reproducible example)? The goal of a reprex is to make it as easy as possible for me to recreate your problem so that I can fix it: please help me help you! If you've never heard of a reprex before, start by reading about the reprex package, including the advice further down the page. Please make sure your reprex is created with the reprex package as it gives nicely formatted output and avoids a number of common pitfalls.

@hadley hadley added the reprex needs a minimal reproducible example label Feb 28, 2022
@hadley hadley closed this as completed Oct 30, 2023
@hadley
Copy link
Member

hadley commented Oct 30, 2023

I've closed this issue due to lack of requested reprex. If you still care about this bug, please open a new issue with a reprex.

@discoleo
Copy link
Author

Unfortunately, I do not remember the details anymore. It may have been something like this - but i will have to check:

  1. Search a nodeset using an initial XPATH, e.g. a set of PubMed articles in a larger xml matching some search criteria;
  2. extract the year of publication as a numeric value, using another XPATH (which has some additional tokens in the path);

Some articles may lack the Year-field. I think that the vapply will generate an error. I will need to check when I have some time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
reprex needs a minimal reproducible example
Projects
None yet
Development

No branches or pull requests

2 participants