Skip to content

Empty tag can cause toRelational() fcn to error with "Can't convert replace <character> to match type of data <logical>" #4

Open
@mskyttner

Description

@mskyttner

Thanks for this nice package!

I discovered an issue where an empty tag (see below) can cause toRelational() to fail, see reproducible example below:

# this xml fragment has an empty title tag (nested under relatedItem)
doc_err <- '<xml>
  <titleInfo lang="eng"><title>CreativeBot</title></titleInfo>          
  <relatedItem type="host">
    <titleInfo><title></title></titleInfo>
  </relatedItem>
</xml>
'

# this statement gives an error
doc_err |> xml2relational::toRelational()

# Error in `vec_assign()`:
# ! Can't convert `replace` <character> to match type of `data` <logical>.
# Run `rlang::last_error()` to see where the error occurred.

# this xml fragment is equal to the previous apart except for using a space instead inside the title tag (nested under relatedItem)
doc_ok <- '<xml>
  <titleInfo lang="eng"><title>CreativeBot</title></titleInfo>          
  <relatedItem type="host">
    <titleInfo><title> </title></titleInfo>
  </relatedItem>
</xml>
'

# this statement works ok
doc_ok |> xml2relational::toRelational()

I think https://github.com/jsugarelli/xml2relational/blob/master/R/xml2relational.r#L105 is what is triggering the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions