I try to set my default encoding to UTF-8; up to now without success:
a <- "Hallo"
b <- "??fd"
print(Encoding(a))
# [1] "unknown"
print(Encoding(b))
# [1] "latin1"
options(encoding = "UTF-8")
a <- "Hallo"
b <- "??fd"
print(Encoding(a))
# [1] "unknown"
print(Encoding(b))
# [1] "latin1"
old_locale <- Sys.getlocale()
Sys.setlocale(category = "LC_ALL", locale = "English_United States.1252")
a <- "Hallo"
b <- "??fd"
print(Encoding(a))
# [1] "unknown"
print(Encoding(b))
# [1] "latin1"
Sys.getlocale()
# [1] "LC_COLLATE=German_Switzerland.1252;
# LC_CTYPE=German_Switzerland.1252;
# LC_MONETARY=German_Switzerland.1252;
# LC_NUMERIC=C;LC_TIME=German_Switzerland.1252"
I found the following links R Encoding for files and How to use Sys.setlocale() but as you can see it seems they don't work in my case and I don't understand why.
I also tried Sys.setlocale(category = "LC_ALL", locale = "en_US.UTF-8")
but got
Warning message: In Sys.setlocale(category = "LC_ALL", locale =
"en_US.UTF-8") : OS reports request to set locale to "en_US.UTF-8"
cannot be honored
In cmd
the command systeminfo & pause
gives
Systemgebietsschema: de-ch;Deutsch (Schweiz)
Eingabegebietsschema: de-ch;Deutsch (Schweiz)
Edit:
- I fear that
"unknown"
encoding could lead to mistakes which I am not aware and
- I thought that it was good to use the new standard UTF-8 to avoid problems like the one I had.
- Last but not least I would like to be able to get reproducible results - a colleague is working on a Mac (with less issues concerning encoding)...
Edit2: What is the experience with this issue? Is there any best practice?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…