convert HTML Character Entity Encoding in R

后端 未结 3 1017
情话喂你
情话喂你 2020-12-05 03:07

Is there a way in R to convert HTML Character Entity Encodings?

I would like to convert HTML character entities like & to & o

3条回答
  •  攒了一身酷
    2020-12-05 03:46

    Unescape xml/html values using xml2 package:

    unescape_xml <- function(str){
      xml2::xml_text(xml2::read_xml(paste0("", str, "")))
    }
    
    unescape_html <- function(str){
      xml2::xml_text(xml2::read_html(paste0("", str, "")))
    }
    

    Examples:

    unescape_xml("3 < x & x > 9")
    # [1] "3 < x & x > 9"
    unescape_html("€ 2.99")
    # [1] "€ 2.99"
    

提交回复
热议问题