Converter entidade HTML no caractere apropriado R
Alguém sabe de uma função genérica em r que pode converterä
ao seu caractere unicodeâ
? Eu já vi algumas funções que absorvemâ
e converta-o em um caractere normal. Qualquer ajuda seria apreciada. Obrigado.
Edit: Abaixo está um registro de dados, que eu provavelmente tenho mais de 1 milhão de registros. Existe uma solução mais fácil que não seja a leitura dos dados em um vetor maciço e, para cada elemento, a alteração dos registros?
wine/name: 1999 Domaine Robert Chevillon Nuits St. Georges 1er Cru Les Vaucrains
wine/wineId: 43163
wine/variant: Pinot Noir
wine/year: 1999
review/points: N/A
review/time: 1337385600
review/userId: 1
review/userName: Eric
review/text: Well this is awfully gorgeous, especially with a nicely grilled piece of Copper River sockeye. Pine needle and piercing perfume move to a remarkably energetic and youthful palate of pure, twangy, red fruit. Beneath that is a fair amount of umami and savory aspect with a surprising amount of tannin. Lots of goodness here. Still quite young but already rewarding at this stage.
wine/name: 2001 Karthäuserhof Eitelsbacher Karthäuserhofberg Riesling Spätlese
wine/wineId: 3058
wine/variant: Riesling
wine/year: 2001
review/points: N/A
review/time: 1095120000
review/userId: 1
review/userName: Eric
review/text: Hideously corked!
Atualização: O uso da função stri_trans_general converterá qualquerÂ
para um caractere minúsculo correto e é necessário atribuir os resultados da aplicação para salvar as alterações.
#cellartracker-10records is the test file to use
tester <- "/Users/petergensler/Desktop/Wine Analysis/cellartracker-10records.txt"
decode <- function(x) { xmlValue(getNodeSet(htmlParse(tester), "//p")[[1]]) }
#Using vector, as we want to iterate over the raw file for cleaning
poop <- vapply(tester, decode, character(1), USE.NAMES = FALSE)
#Now use stringi to convert all characters to correct characters poop
poop <- stringi::stri_trans_general(poop, "Latin-ASCII")
writeLines(poop, "wines.txt")