Best practice: Should I try to change to UTF-8 as locale or is it safe to leave it as is?
encoding, r, utf-8, windows
Solution
This is not a perfect answer but a good workaround: As Roland pointed out, it might be dangerous to change the locale. So leave it as is. If you have a file and you run into trouble, just search for non-UTF8 encoding as discribed here for `RStudio`. What I saw, most Editors have such a feature.
Furthermore, this answer gives more insight in what you can do in case you `source()` a file.
For a way to deal with locales when collations play a crucial part see here
Edit some years later: I realized, that Windows allows you to change some settings which also affects R/RStudio:
In this German setting e.g. (after restart RStudio):
format(Sys.time(), "%a")
# [1] "Mo" # without "."
Then...
In this Swiss setting e.g. (after restart RStudio):
format(Sys.time(), "%a")
# [1] "Mo." # WITH "."
Although this setting does NOT affect `LC_TIME=German_Switzerland.1252`
Problem
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?