Skip to content

as_list() return element text as character, not list #215

@StevenMMortimer

Description

@StevenMMortimer

Issue Description

as_list() will convert element text into a list of length 1 with a single character element. I would expect it to "simplify" or "unbox" the text so it is not a list. The XML package already has this type of behavior in using xmlToList().

Reproducible Example

In the example below the "bar" element text "Hello" is represented as a list. I would expect it to be a character string.

library(xml2)
as_list(read_xml("<bar>Hello</bar>")) 
#> $bar
#> $bar[[1]]
#> [1] "Hello"

# the desired result would be
#> $bar
#> [1] "Hello"

The XML package has similar style to the more desirable behavior.

library(XML)
xmlToList(newXMLNode("bar","Hello"))
#> [1] "Hello"

Metadata

Metadata

Assignees

No one assigned

    Labels

    featurea feature request or enhancement

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions