I would like to convert HTML character entities like &
to &
or >
to >
For Perl exists the package HTML::Entities which could do that, but I couldn't find something similar in R.
I also tried iconv()
but couldn't get satisfying results. Maybe there is also a way using the XML
package but I haven't figured it out yet.
Unescape xml/html values using xml2
package:
unescape_xml <- function(str){ xml2::xml_text(xml2::read_xml(paste0("<x>", str, "</x>"))) } unescape_html <- function(str){ xml2::xml_text(xml2::read_html(paste0("<x>", str, "</x>"))) }
Examples:
unescape_xml("3 < x & x > 9") # [1] "3 < x & x > 9" unescape_html("€ 2.99") # [1] "€ 2.99"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With