Skip to content

xml_find_num: should handle missing node; #356

Description

@discoleo

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);

Activity

  1. hadley commented on Feb 28, 2022

    @hadley
    Member

    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.

  2. added
    reprexneeds a minimal reproducible example
    on Feb 28, 2022
  3. hadley commented on Oct 30, 2023

    @hadley
    Member

    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.

  4. discoleo commented on Oct 30, 2023

    @discoleo
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    reprexneeds a minimal reproducible example

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions