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_length() on empty nodeset #404

Open
mgirlich opened this issue Aug 29, 2023 · 3 comments
Open

xml_length() on empty nodeset #404

mgirlich opened this issue Aug 29, 2023 · 3 comments
Labels
bug an unexpected problem or unintended behavior

Comments

@mgirlich
Copy link
Contributor

xml_length(xml_nodeset()) returns 0 but I feel this should rather be integer() which would also be consistent with e.g. xml_name().

library(xml2)

(ns1 <- xml2:::xml_nodeset())
#> {xml_nodeset (0)}
xml_length(ns1)
#> [1] 0
(ns2 <- xml2:::xml_nodeset(list(xml_missing()), deduplicate = FALSE))
#> {xml_nodeset (1)}
#> [1] <NA>
xml_length(ns2)
#> [1] 0

Created on 2023-08-29 with reprex v2.0.2

@hadley
Copy link
Member

hadley commented Oct 30, 2023

Agreed

@hadley hadley added the bug an unexpected problem or unintended behavior label Oct 30, 2023
@discoleo
Copy link

discoleo commented Nov 3, 2023

My mistake!

I misinterpreted it as length(node_set).

Old

I do not fully understand this issue:

xml_length: should return the length of the node-set, which should be 0 if there are no nodes. The length is always a numeric value, which can be 0, or NA if its unknown.

It is xml_missing which is ill-defined: does it count as a node?

@hadley
Copy link
Member

hadley commented Nov 3, 2023

xml_length() returns a vector the same length as its input. It's the length of each element of the nodeset, not the length of the nodeset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

3 participants