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_attr()<-is mishandling xml_nodesets #221

eamoncaddigan opened this issue May 7, 2018 · 1 comment

xml_attr()<-is mishandling xml_nodesets #221

eamoncaddigan opened this issue May 7, 2018 · 1 comment


Copy link

@eamoncaddigan eamoncaddigan commented May 7, 2018

When assigning a character vector to an xml_nodeset using xml_attr()<-, the first element in the vector is assigned to all nodes. This is different than, e.g., xml_text()<-, which allows different values to be assigned to different nodes.

Reproducible Example

x <- read_xml("<x><a b='c'/><a b='d'/></x>")
a_set <- xml_find_all(x, "a")
# Doesn't work as expected
xml_attr(a_set, "b") <- c("e", "f")
xml_attr(a_set, "b")
#> [1] "e" "e"
# Also doesn't work as expected
xml_set_attr(a_set, "b", c("g", "h"))
xml_attr(a_set, "b")
#> [1] "g" "g"

I understand that xml_attrs() can be used to set the same attribute for multiple nodes. However, since the current behavior is (IMO) unexpected I believe it should at least be reflected in the documentation.

@jimhester jimhester added the bug label May 7, 2018

This comment has been minimized.

Copy link

@jimhester jimhester commented May 7, 2018

I think you are right, xml_attr<- should be recycling the attributes.

@jimhester jimhester closed this in c8f56a1 Jul 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.