What is my encoding?
Imagine that you have a file but you don't know what is the encoding. Here is a way to determine it:
Let create a file with Excel using the function "Save as" and then choose, Text (separator : tabulation) (.txt)
How to read it ?
> file.name <- "path to the file"
> x <- unlist(lapply(iconvlist(), function(enc) try(read.table(file.name, fileEncoding=enc, nrows=1, header=FALSE, sep="\t"), silent = TRUE)))
If the first cell contains Ebodjé for example:
> z <- lapply(x, function(y) {y=="ebodjé"})
> which(unlist(z))
CSMACINTOSH MAC MACARABIC MACCENTRALEUROPE MACCROATIAN MACGREEK
126 330 331 332 333 335
MACHEBREW MACICELAND MACINTOSH MACROMAN MACROMANIA MACTURKISH
336 337 338 339 340 342
Let create a file with Excel using the function "Save as" and then choose, Text (separator : tabulation) (.txt)
How to read it ?
> file.name <- "path to the file"
> x <- unlist(lapply(iconvlist(), function(enc) try(read.table(file.name, fileEncoding=enc, nrows=1, header=FALSE, sep="\t"), silent = TRUE)))
If the first cell contains Ebodjé for example:
> z <- lapply(x, function(y) {y=="ebodjé"})
> which(unlist(z))
CSMACINTOSH MAC MACARABIC MACCENTRALEUROPE MACCROATIAN MACGREEK
126 330 331 332 333 335
MACHEBREW MACICELAND MACINTOSH MACROMAN MACROMANIA MACTURKISH
336 337 338 339 340 342
An alternative is to use:
readr::guess_encoding()
or
stringi::stri_enc_detect()
Commentaires
Enregistrer un commentaire