232

I would like install R on my laptop Mac OS X version 10.7.3

I downloaded the last version and I double click on it and it was installed, when i start up I get the following error, I searched in internet but I could not solve the problem, any help would be appreciated

the errors are

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_PAPER failed, using "C"
[R.app GUI 1.50 (6126) x86_64-apple-darwin9.8.0]

WARNING: You're using a non-UTF8 locale, therefore only ASCII characters will work. Please read R for Mac OS X FAQ (see Help) section 9 and adjust your system preferences accordingly. [History restored from /Users/nemo/.Rapp.history]

  • 3
    Oh, I just wrote in terminal defaults write org.R-project.R force.LANG en_US.UTF-8 and then it solved ( i do not have any message or error) I have another question, how to import my data? where i should copy my data for example if they are in desktop and saved in txt, how can i import them? –  Mar 13 '12 at 17:50
  • 1
    refere these links for details http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Internationalization-of-the-R_002eapp http://support.rstudio.org/help/discussions/questions/247-system-locale-on-mac-os-x-set-by-default-to-an-utf-8 – Abhishek Gayakwad Jan 07 '13 at 10:09
  • The links provided by @AbhishekGayakwad (thanks to him) explains the answer below. – Unheilig Apr 13 '15 at 07:16

7 Answers7

492
  1. Open Terminal
  2. Write or paste in: defaults write org.R-project.R force.LANG en_US.UTF-8
  3. Close Terminal (including any RStudio window)
  4. Start R

For someone runs R in a docker environment (under root), try to run R with below command,

LC_ALL=C.UTF-8 R
# instead of just `R`
Anh-Thi DINH
  • 1,845
  • 1
  • 23
  • 17
nassimhddd
  • 8,340
  • 1
  • 29
  • 44
  • 6
    This works for me as well. Thanks! http://cran.r-project.org/bin/macosx/RMacOSX-FAQ.html#Internationalization-of-the-R_002eapp – Bhoom Suktitipat Sep 05 '13 at 09:54
  • 65
    What's going on actually behind this ? – WoooHaaaa Dec 03 '13 at 06:32
  • Does this work in OSX 10.9.1? I get the same warnings except #1 and #5 with R 3.0.2. I installed R by Brew package manager. – Léo Léopold Hertz 준영 Jan 24 '14 at 21:39
  • 1
    Thanks! @Masi yes it does! In addition to you Masi, I would highly recommend installing from the CRAN repos. http://cran.r-project.org/mirrors.html select a mirror that fits you and then pick packages you want to install, it should be pretty straightforward! Good luck! – nemesis Feb 11 '14 at 21:27
  • Works in OS X 10.11 El Capitan. – vrepsys Oct 14 '15 at 15:46
  • 13
    In my system (OS X 10.11 El Capitán) I have environment variables `LANG` and `LC_ALL` set to `en_US.UTF-8` for my terminal (in the `~/.bash_profile` file), and command line R does not display those warning messages; but R Studio does. Found that R Studio uses the _System Preferences > Language & Region_ settings. Which in my system are: _English_ for the language and _Spain_ for the Region. This leads to a `en_ES` locale, not supported by the system. Found that I can set an specific setting for Mac R Studio with this command: `defaults write org.rstudio.RStudio force.LANG en_US.UTF-8` – Ramón Gil Moreno Aug 26 '16 at 11:06
  • 1
    @RamónGilMoreno It seems that setting the language of R-project solves the problem for both R and R Studio. So I guess it is a better approach. – Yongwei Wu Nov 12 '16 at 07:14
  • @yongwei-wu Yep. Definitely. Setting `org.R-project.R` is the accepted answer. The `org.rstudio.RStudio` setting complements it in the case you (as me) want some locale flexibility on the command line. – Ramón Gil Moreno Nov 15 '16 at 12:22
  • It works for local R but the warning still appears in remote R via ssh which populates those locale variables to remote. – Kun Ren Jun 25 '17 at 14:09
85

Setting locales in terminal resolved the issue for me. Open the terminal and

  1. Check if locale settings are missing

    > locale
    LANG=
    LC_COLLATE="C"
    LC_CTYPE="UTF-8"
    LC_MESSAGES="C"
    LC_MONETARY="C"
    LC_NUMERIC="C"
    LC_TIME="C"
    LC_ALL=
    
  2. Edit ~/.profile or ~/.bashrc

    export LANG=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    
  3. Run . ~/.profile or . ~/.bashrc to read from the file.

  4. Open a new terminal window and check that the locales are properly set

    > locale
    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"
    
Community
  • 1
  • 1
  • you made my day, that solved the issue of Rstudio too, which reported at https://support.rstudio.com/hc/communities/public/questions/200651966-Locale-issues-unable-to-start-or-connect-to-Rstudio-server – Islam El Hosary Feb 22 '15 at 19:02
  • When I am running R script to plot `svg` using `Rscript` in bash on osx, I get this warning. Solution: `export LANG=en_US.UTF-8` `export LC_ALL=en_US.UTF-8` and solution: writting `Sys.setenv(LC_ALL="en_US.UTF-8")` in script following Bhoom Suktitipat 's answer all work for me. – Nick Dong Mar 21 '17 at 07:43
  • 2
    You might want to add that if you are running zsh, you need to edit `~/.zshrc`. – cbrnr Sep 25 '18 at 09:25
  • This didn't change the locale in my terminal; only changing `~/.bash_profile` worked correctly; see here for more https://apple.stackexchange.com/a/51038/257940 – MichaelChirico Sep 26 '18 at 02:04
  • This solution worked for me as well, on Manjaro Linux with Code warning about missing locales (running R from terminal was fine). – Waldir Leoncio Jan 16 '20 at 05:18
  • Nice, that it also works fine on Ubuntu Linux – Ilona Feb 22 '21 at 09:00
27

Just open the R(software) and copy and paste

system("defaults write org.R-project.R force.LANG en_US.UTF-8")

Hope this will work fine or use the other method

open(on mac): Utilities/Terminal copy and paste

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

and close both terminal and R and reopen R.

Blazemonger
  • 90,923
  • 26
  • 142
  • 180
user3512330
  • 279
  • 3
  • 2
  • Pasting in the Terminal did not work for me, this oneliner did work. It might be because of insufficient user rights. – CousinCocaine Feb 18 '16 at 10:03
  • 1
    Where is the Utilities? Not working in macOS Sierra 10.12.1 :( Can you check [this](http://stackoverflow.com/questions/41873359/r-encoding-failing-with-umlauts-such-as-ä-and-ö) on the same issue in OS X? – hhh Jan 27 '17 at 11:33
7

I found slightly different problem running R on through mac terminal, but connecting remotely to an Ubuntu server, which prevented me from successfully installing a library.

The solution I have was finding out what "LANG" variable is used in Ubuntu terminal

Ubuntu > echo $LANG
en_US.TUF-8

I got "en_US.TUF-8" reply from Ubuntu.

In R session, however, I got "UTF-8" as the default value and it complained that LC_TYPEC Setting LC_CTYPE failed, using "C"

R> Sys.getenv("LANG")
"UTF-8"

So, I tried to change this variable in R. It worked.

R> Sys.setenv(LANG="en_US.UTF-8")
Bhoom Suktitipat
  • 2,147
  • 2
  • 17
  • 11
1

I got same issue on Catalina mac. I also installed the R from the source in following diretory. ./Documents/R-4.0.3

Now from the terminal type

 ls -a 

and open

 vim .bash_profile 

type

export LANG="en_US.UTF-8"

save with :wq

then type

source .bash_profile 

and then open

./Documents/R-4.0.3/bin/R 
./Documents/R-4.0.3/bin/Rscript 

I always have to run "source /Users/yourComputerName/.bash_profile" before running R scripts.

ankit agrawal
  • 301
  • 1
  • 14
-1

Tks Ramon Gil Moreno. Pasting in Terminal and then restarting R Studio did the trick:
write org.rstudio.RStudio force.LANG en_US.UTF-8

Environment: MAC OS High Sierra 10.13.1 // RStudio version 3.4.2 (2017-09-28) -- "Short Summer"

Ennio De Leon

  • Writing an answer that merely repeats what other answers already say adds zero value, and is frowned upon. Doubly so when the new answer additionally contains errors. – Konrad Rudolph May 09 '23 at 12:12
-2

On my Mac r is installed in /usr/local/bin/r, add line below in .bash_profile solved the same problem:

alias r="LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 r"
adietster
  • 1
  • 1