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

Duplicated names for elements in list after calling as_list #436

Open
pepijn-devries opened this issue Dec 30, 2023 · 0 comments
Open

Duplicated names for elements in list after calling as_list #436

pepijn-devries opened this issue Dec 30, 2023 · 0 comments

Comments

@pepijn-devries
Copy link

pepijn-devries commented Dec 30, 2023

Thanks for your work on xml2!

Consider the following reprex where I have an xml document with multiple nodes of the same element (item):

a <- xml2::as_xml_document("<collection><item>foo</item><item>bar</item></collection>")
b <- xml2::as_list(a)

## This will only show "foo" but not "bar"
b$collection$item
#> [[1]]
#> [1] "foo"

## However both elements are there:
names(b$collection)
#> [1] "item" "item"
b$collection[[1]]
#> [[1]]
#> [1] "foo"
b$collection[[2]]
#> [[1]]
#> [1] "bar"

Created on 2023-12-30 with reprex v2.0.2

When the xml document in the reprex is converted to a list, the list elements will have duplicated names. Which I think is undesirable in R, and will cause all sorts of problems. Would it be possible to either:

  1. Throw a warning when as_list produces duplicated element names; or
  2. Repair the names such that they become unique.

Thanks for considering.

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

No branches or pull requests

1 participant