24

The following output can be obtained after installation of R by homebrew and without in my OSX:

During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_MONETARY failed, using "C"         # this line is not occurring in OSX 10.10.1 Yosemite but other four are.

I found an existing question but the solution does not work for me. I do this

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

and the warning messages are still shown. I guess this works when installing R using the package from the R project page.

How to get rid of these warning messages after installation of R in OSX?

Community
  • 1
  • 1
Jan Deinhard
  • 19,645
  • 24
  • 81
  • 137
  • @RichardScriven, I'm sure it's a great suggestion but I don't quite follow. I'm running R in a terminal. There is no app in my Application directory. I know there is one when installing R with installer package from the project page. – Jan Deinhard Dec 04 '14 at 17:35
  • You are right. I removed the tag. – Jan Deinhard Dec 05 '14 at 07:09
  • I get the same errors without the line "5: - -" in Yosemite 10.10.1 which are actually likely different from the post which I said to be duplicate: http://stackoverflow.com/questions/9689104/installing-r-on-mac-warning-messages-setting-lc-ctype-failed-using-c There may be the same problem in the topics. I actually installed R without homebrew and I get the same problem so I recommend to remove Homebrew in title and body. – Léo Léopold Hertz 준영 Jan 25 '15 at 20:48
  • this error message is really irritating one... anyways, can someone also tell how to create a customized library for storing packages from cran. it seems on mac os x the default directory has issues... – Manoj Kumar Aug 09 '16 at 07:09

5 Answers5

18

Problem: Locale variables indicating what encoding to use are not set. To see the issue, in Terminal, type locale, and you likely get something like

LANG=
LC_COLLATE=
LC_CTYPE=
LC_MESSAGES=
LC_MONETARY=
LC_NUMERIC="en_US.UTF-8"
LC_TIME=
LC_ALL=

LC_NUMERIC may or may not be set, but given your errors, the rest are either not set or set to something R can't use. If those variables are empty, R is going to complain. To fix the problem:

Option 1: Terminal Preferences Go to Terminal's Preferences. Under the "Advanced" tab, make sure "Text Encoding" is set to "Unicode (UTF-8)" (or whatever you need). Make sure the checkbox underneath for "Set locale environment variables on startup" is checked. Unchecking it tends to leave locale variables unset or as "C", unless you've changed .bash_profile, .bashrc, or .profile (depending on your system). That may be enough to fix your problem. If not:

Option 2: Set from R To set them from inside of R, type

R> Sys.setenv(LANG="en_US.UTF-8")
R> Sys.setenv(LC_ALL="en_US.UTF-8")

...which should set all of the variables R is complaining about.

Option 3: Set from Terminal To set them from Terminal, type

export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

...which should set the rest of the variables R is complaining about.

Check: In Terminal, type locale again. You should get

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

Restart R, and you should be set.

alistaire
  • 42,459
  • 4
  • 77
  • 117
  • 1
    I did everything as you instructed but do not get the output of locale as you say. I get *LANG= ; LC_COLLATE="C"; LC_CTYPE="en_US.UTF-8"; LC_MESSAGES="C"; LC_MONETARY="C"; LC_NUMERIC="C"; LC_TIME="C"; LC_ALL=*;" Any other option? – Léo Léopold Hertz 준영 Jan 28 '15 at 08:32
  • When do you get that? After manually setting the variables à la "Option 3", but before resetting, it should look like the "Check" locale. If it resets when you restart Terminal, it's either because the checkbox in Terminal's Prefs is not checked, or because you've got different startup instructions for bash in .bash_profile, .bashrc, or .profle (on OS X, it should be .bash_profile). The OS X "Language & Region" prefpane (name varies by OS X version) can impact locale as well, but that doesn't sound like what's happening here. – alistaire Jan 29 '15 at 18:43
15

For R this is what worked from the terminal

$ defaults write org.R-project.R force.LANG en_US.UTF-8

See Installing R on Mac - Warning messages: Setting LC_CTYPE failed, using "C"

Axeman
  • 32,068
  • 8
  • 81
  • 94
peter_v
  • 362
  • 2
  • 8
4

Put the following to your $HOME/.bashrc

export LANG=en_US.UTF-8

It seems, that for some reason, the $HOME/.profile is not sourced in starting the terminal.

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
2

Related to alistaire answer, I only changed the LANG variable on my ~/.profile file:

export LANG=en_US.UTF-8

Then, restart the terminal session (or source ~/.profile) and off you go.

2

I opened System Preferences/Language and Region and selected United States as my Region, all warnings dissapeared.

Ignacio
  • 21
  • 1