R - removal of accents in a line

I have a library with html files and in files_dep I have a list of them. I need to convert the text stored in them to a table, but the problem is that they have accents and -. I wrote this to read it and work fine.

for (i in files_dep) { text<-readLines(i,encoding="UTF-8") aa<-paste(text, collapse=' ') if (grepl(empieza,aa) & grepl(termina,aa)) { nota=gsub(paste0("(^.*", empieza, ")(.*?)(", termina, ".*)$"), "\\2", aa) #nota<-iconv(nota,to="ASCII//TRANSLIT") df<-rbind(df, data.frame(fileName=i, nota=nota)) }} 

I can read things like:

 Este sábado enfrentarán a un equipo. 

Therefore, I only need to remove the accents. I tried to uncomment

 nota <- iconv(nota,to="ASCII//TRANSLIT") 

but I get:

  Este sA!bado se enfrentarA!na un equipo. 

So, I do not know what the problem is.

In addition, I need to remove accents and all special characters. Thanks

Edition:

I took the latest data stored in nota at the end of the loop. This is what I see:

 nota [1] " <p>La inclusión del seleccionado argentino en el viejo Tres Naciones significó, hace tres años, la confirmación de que el nivel del rugby argentino estaba a la altura de los grandes equipos del planeta, aunque se preveía que esa transición entre ser un equipo <em>del montón</em>&nbsp;a formar parte de la<em> elite </em>no iba a ser sencilla<em>. </em>Hoy, luego de dos años de competencia en el Rugby Championship, Los Pumas están cada vez más cerca de dar el batacazo y conseguir su primer triunfo en la historia del torneo.</p><p> 

If I do this:

 iconv(nota,to="ASCII//TRANSLIT") 

I get:

 iconv(nota,to="ASCII//TRANSLIT") [1] " <p>La inclusiA3n del seleccionado argentino en el viejo Tres Naciones significA3, hace tres aA?os, la confirmaciA3n de que el nivel del rugby argentino estaba a la altura de los grandes equipos del planeta, aunque se preveA-a que esa transiciA3n entre ser un equipo <em>del montA3n</em>&nbsp;a formar parte de la<em> elite </em>no iba a ser sencilla<em>. </em>Hoy, luego de dos aA?os de competencia en el Rugby Championship, Los Pumas estA!n cada vez mA!s cerca de dar el batacazo y conseguir su primer triunfo en la historia del torneo. 
+5
source share
1 answer

When I ran into a similar problem, I used the stri_trans_general function from the stringi package. For example, you can try: stri_trans_general(nota,"Latin-ASCII")

+14
source

Source: https://habr.com/ru/post/1204779/


All Articles