Nettoyer le projet des caracteres non ASCII
Faire tourner sur le projet le script de ThinkR parcourant les fichiers du projet et remplaçant les caractères non ASCII par leur équivalent unicode.
Le script n'est pas encore packagé, il n'est pas robuste à 100%
# Clean non-ASCII character ----
chars <- c(
"à", "â",
"é", "è", "ê",
"î", "ï",
"ô", "ö", "ø",
"æ", "œ",
"ù",
"ç",
"'", "²",
"€"
)
files <- list.files("R", full.names = TRUE, pattern = ".R$")
for (file in files) {
# file <- files[23]
lines <- readr::read_lines(file) # Test if non-ascii characters
asc <- iconv(lines, "latin1", "ASCII")
ind_rox <- which((is.na(asc) | asc != lines) & grepl("^#'", lines))
ind_no_rox <- which((is.na(asc) | asc != lines) & !grepl("^#'", lines)) if (length(ind_rox) != 0) { for (char in chars) {
lines[ind_rox] <- stringi::stri_replace_all_coll(
lines[ind_rox],
char,
paste0("\\", stringi::stri_trans_general(char, "hex"))
)
} }
if (length(ind_no_rox) != 0) {
for (char in chars) {
lines[ind_no_rox] <- stringi::stri_replace_all_coll(
lines[ind_no_rox],
char,
stringi::stri_trans_general(char, "hex")
)
}
}
if (length(c(ind_rox, ind_no_rox)) != 0) {
readr::write_lines(lines, file)
}
asc <- iconv(lines, "latin1", "ASCII")
ind_rox <- which((is.na(asc) | asc != lines) & grepl("^#'", lines))
ind_no_rox <- which((is.na(asc) | asc != lines) & !grepl("^#'", lines)) if (length(ind_rox) != 0 | length(ind_no_rox) != 0) if (length(ind_rox) != 0 | length(ind_no_rox) != 0){
warning("Some character of file '", file, "' have not been converted in lines:", paste(ind_rox, ind_no_rox))
}
cat(crayon::green(file, "should be clean"))
}