66

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: How to change language settings 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)

Roman Luštrik
  • 69,533
  • 24
  • 154
  • 197
Tobias Schula
  • 789
  • 1
  • 5
  • 6
  • 1
    Have you tried `LANG` between quotes and/or unshortened (i.e., `LANGUAGE`)? Anyway, I'm not sure this is the way to approach the issue; my system shows errors in English even though `Sys.getlocale` shows `Portuguese_Brazil.1252` all around. – Waldir Leoncio Dec 27 '13 at 14:05

11 Answers11

59

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

Sys.setlocale("LC_ALL","English")
Andi
  • 778
  • 7
  • 15
  • 1
    This does not change language of the error messages in my cases (Ubuntu + OSX), try e. g. `log("a")` and check the language of the error message – R Yoda Dec 26 '17 at 13:40
  • 3
    "Warning message: In `Sys.setlocale("LC_ALL", "English")`: OS reports request to set locale to "English" cannot be honored" – bers Sep 16 '21 at 09:57
  • 1
    The reason is that locales are platform-specific. `"English"` works on Windows, but not on OpenSUSE Leap 15.2, for example. – bers Sep 16 '21 at 10:35
17
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.

wtk
  • 1,033
  • 10
  • 15
13

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
MichaelChirico
  • 33,841
  • 14
  • 113
  • 198
  • I think its important to start R with the locale pre-set this way, particularly if you need to mess with LC_CTYPE or LC_ALL. In my case, I was setting `LC_ALL` to `ja_JP.SJIS` and I had to also change my terminal's encoding. Worked like a charm. – BrodieG Jun 25 '20 at 01:16
9

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.

alberto
  • 2,625
  • 4
  • 29
  • 48
7

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).

R Yoda
  • 8,358
  • 2
  • 50
  • 87
6

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.

jangorecki
  • 16,384
  • 4
  • 79
  • 160
4

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

demongolem
  • 9,474
  • 36
  • 90
  • 105
Pablo
  • 41
  • 2
3

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.

IRTFM
  • 258,963
  • 21
  • 364
  • 487
  • For completeness can you also try values of "EN" and "en_GB"? After taht I would think it needful to establish whether the EN file ahs been lost or damaged. – IRTFM May 02 '13 at 23:04
  • I tried several other variations of "EN", but R stays in German. I Don’t think the EN file is lost or damaged, because starting R with `"LANG="C"` works. – Tobias Schula May 03 '13 at 09:03
2

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

Jia Yang
  • 41
  • 2
2

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

1

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')
Tomizono
  • 104
  • 2