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

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

Open
mskyttner opened this issue Feb 9, 2023 · 1 comment

Comments

@mskyttner
Copy link

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.

@mskyttner
Copy link
Author

It works better when having using a pairlist() instead of a c() at https://github.com/jsugarelli/xml2relational/blob/master/R/xml2relational.r#L97

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