How to change the locale of R?

RLocale

R Problem Overview


I’m using R version 2.15.3 (2013-03-01) on Ubuntu 12.10. The System is in German and so is R. This comes unhandy when searching for error messages.

Executing R in xterm this way $ LANG="C" R partially solves the issue. Then R displays everything in English. But when loading RStudio this way, the R interpreter is still in German. So I’m looking for a way to change the locale of R in R itself.

I found this: https://stackoverflow.com/questions/13575180/how-to-change-the-language-of-errors-in-r, but Sys.setenv(LANG = "en") does’t work for me:

2+x
# Fehler: Objekt 'x' nicht gefunden
Sys.setenv(LANG = "en")
2+x
# Fehler: Objekt 'x' nicht gefunden

I also tried Sys.setenv(LANG = "en_US.UTF-8") with no success.

Output of Sys.getlocale()

Sys.getlocale()
# [1] "LC_CTYPE=de_DE.UTF-8;LC_NUMERIC=C;LC_TIME=de_DE.UTF-8;
# LC_COLLATE=de_DE.UTF-8;LC_MONETARY=de_DE.UTF-8;LC_MESSAGES=de_DE.UTF-8;
# LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=de_DE.UTF-8;
# LC_IDENTIFICATION=C"

(linebrakes added for convenience)

R Solutions


Solution 1 - R

Just had the same problem and found the solution that worked for me on Windows/Linux:

Sys.setlocale("LC_ALL","English")

Solution 2 - R

Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8')
Sys.setenv(LANG = "en_US.UTF-8")

This 2 worked for me. No more polish error messages in eclipse R. Though I think only the 2nd had effect. Thanks

edit: although I have to execute those every time i restart R environment.

Solution 3 - R

If you want to do this temporarily, you can try starting R from the command line preceded by setting the language in-line:

# start R with LANGUAGE set to Mandarin
LANGUAGE=zh_CN.UTF-8 R --no-save
# do R stuff
q()
# any LANGUAGE set in your env will be unaffected afterwards
env | grep LANGUAGE

Solution 4 - R

In Ubuntu (14.04) this is the solution that worked for me:

Edit the .Renviron file in your home directory and add this line:

LANGUAGE="en_US.utf8"
# for R with British accent use en_GB.utf8

Then restart R.

Solution 5 - R

In my cases (OSX High Sierra + Ubuntu 14.04) I could switch the language of R output to English only by using this command (with immediate effect without restarting the R session):

Sys.setenv("LANGUAGE"="EN")

To permanently change the language either add the above line to your Rprofile.site file (see ?Startup) or create/edit the file .Renviron in your home folder (~/) and enter a line with LANGUAGE=en or similar (like LANGUAGE="fr_FR.utf8" for French with UTF-8 encoding which is used by default in Linux).

Solution 6 - R

Try Sys.setlocale("LC_TIME", "English")

Solution 7 - R

Try:

Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8')

Taken from: http://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Localization-of-messages which should be consulted for further details.

Solution 8 - R

Surprisingly among so many answers I don't see an answer that I would prefer myself.

echo 'LC_ALL=C' >> ~/.Renviron

This will append (or create if doesn't exist) a environment configuration line to .Renviron file which is meant to be used exactly for this purpose.

After that any R process started should already have locale specified in .Renviron file.

Solution 9 - R

I had the same problem. I solved it by changing my Macbook's system preference->region as US. Then, re-install the R. Then, the system language changed ultimately.

> sessionInfo()

locale: [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

Solution 10 - R

You just need to

  1. Open Terminal
  2. Write or paste in: defaults write org.R-project.R force.LANG en_US.UTF-8
  3. Close Terminal and restart R

It worked for me in OS X

Solution 11 - R

I think that is an issue of your Ubuntu, not R. If the OS does not have correct locale setting of "en", the R cannot use it. Check out the OS locales. Or using locale 'C' instead of 'en' may work still.

Sys.setenv(LANG='C')

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionTobias SchulaView Question on Stackoverflow
Solution 1 - RAndiView Answer on Stackoverflow
Solution 2 - RwtkView Answer on Stackoverflow
Solution 3 - RMichaelChiricoView Answer on Stackoverflow
Solution 4 - RalbertoView Answer on Stackoverflow
Solution 5 - RR YodaView Answer on Stackoverflow
Solution 6 - RPabloView Answer on Stackoverflow
Solution 7 - RIRTFMView Answer on Stackoverflow
Solution 8 - RjangoreckiView Answer on Stackoverflow
Solution 9 - RJia YangView Answer on Stackoverflow
Solution 10 - RSusana Isabel SantosView Answer on Stackoverflow
Solution 11 - RTomizonoView Answer on Stackoverflow