How to get rid of warning messages after installing R? [duplicate] - r

This question already has answers here:
Installing R on Mac - Warning messages: Setting LC_CTYPE failed, using "C"
(7 answers)
Closed 4 years ago.
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
Open Terminal
Write or paste in: defaults write org.R-project.R force.LANG en_US.UTF-8
Close Terminal
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?

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.

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"

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.

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.

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

Related

Why is R showing mixed German/French messages when no locale is set?

I’ve installed R 4.2.1 (arm64) from CRAN on macOS Monterey. My system’s preferred language is set to English, yet R uses a weird mix of French and German to show error messages, and this is breaking tests and CI pipelines:
base::xyz
# Fehler: Objekt 'xyz' nicht gefunden
utils::xyz
# Fehler: 'xyz' n’est un object exporté depuis 'namespace:utils'
I have no specific locale set (note in particular the setting of LC_MESSAGES):
$ locale
LANG=""
LC_COLLATE="C"
LC_CTYPE="UTF-8"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=
$ env | grep 'LANG\|LC'
LC_TERMINAL_VERSION=3.4.16
LC_CTYPE=UTF-8
LC_TERMINAL=iTerm2
And this is also what R is seeing:
lapply(.LC.categories, Sys.getlocale) |>
structure(names = .LC.categories, class = 'simple.list')
_
LC_ALL C/UTF-8/C/C/C/C
LC_COLLATE C
LC_CTYPE UTF-8
LC_MONETARY C
LC_NUMERIC C
LC_TIME C
LC_MESSAGES C
LC_PAPER
LC_MEASUREMENT
Furthermore, this behaviour seems to only extend to messages: when parsing or formatting numbers or dates, R’s behaviour is locale independent.
I can stop this behaviour by explicitly setting LC_MESSAGEs or LANG, e.g.:
$ LANG=en_GB.utf-8 Rscript -e 'utils::foo'
Error: 'foo' is not an exported object from 'namespace:utils'
However, I don’t understand why this is required, and where R is getting its weird localisation preference from (especially since LC_MESSAGES is set to C).
For completeness, my current location is in Switzerland, as is my public IP address. And the computer model was purchased on the Swiss Apple Store. But the system’s language is set to English in the Preference Pane (although by default the shell doesn’t seem configured to see this). I should also note that I am launching R via the command line, not via any kind of GUI.

R Console Language Setting [duplicate]

My error messages are displayed in French. How can I change my system language setting so the error messages will be displayed in English?
You can set this using the Sys.setenv() function. My R session defaults to English, so I'll set it to French and then back again:
> Sys.setenv(LANG = "fr")
> 2 + x
Erreur : objet 'x' introuvable
> Sys.setenv(LANG = "en")
> 2 + x
Error: object 'x' not found
A list of the abbreviations can be found here.
Sys.getenv() gives you a list of all the environment variables that are set.
In the case of RStudio for Windows I succeeded in changing the language following the instructions found in R for Windows FAQ, in particular I wrote:
language = EN
inside the file Rconsole (in my installation it is C:\Program Files\R\R-2.15.2\etc\Rconsole); this works also for the command Rscript.
For example you can locate the Rconsole file with this two commands from a command prompt:
cd \
dir Rconsole /s
The first one make the root as the current directory, the second one looks for the Rconsole file.
In the following screenshot you have that Rconsole file is in the folder C:\Program Files\R\R-3.4.1\etc.
You may have more than one location, in that case you may edit all the Rconsole files.
After that you can open the Rconsole file with your favorite editor and look for the line language = and then append EN at the end of that line.
In the following screenshot the interesting line is the number 70 and you have to append EN at the end of it.
For mac users, I found this on the R for Mac FAQ
If you use a non-standard setup (e.g. different language than
formats), you can override the auto-detection performed by setting
`force.LANG' defaults setting, such as for example
defaults write org.R-project.R force.LANG en_US.UTF-8
when run in Terminal it will enforce US-english setting regardless of the system
setting. If you don't know what Terminal is you can use this R command
instead:
system("defaults write org.R-project.R force.LANG en_US.UTF-8")
but do not forget to quit R and start R.app again afterwards. Please
note that you must always use `.UTF-8' version of the locale,
otherwise R.app will not work properly.
This helped me to change my console language from Chinese to English.
This works from command line :
$ export LANG=en_US.UTF-8
None of the other answers above worked for me
If you use Ubuntu you will set
LANGUAGE=en
in /etc/R/Renviron.site.
You may also want to be aware of the difference between, for example, Sys.setenv(LANG = "ru") and Sys.setlocale(locale = "ru_RU.utf8").
> Sys.setlocale(locale = "ru_RU.utf8")
[1] "LC_CTYPE=ru_RU.utf8;LC_NUMERIC=C;LC_TIME=ru_RU.utf8;LC_COLLATE=ru_RU.utf8;LC_MONETARY=ru_RU.utf8;LC_MESSAGES=en_IE.utf8;LC_PAPER=en_IE.utf8;LC_NAME=en_IE.utf8;LC_ADDRESS=en_IE.utf8;LC_TELEPHONE=en_IE.utf8;LC_MEASUREMENT=en_IE.utf8;LC_IDENTIFICATION=en_IE.utf8"
If you are interested in changing the behaviour of functions that refer to one of these elements (e.g strptime to extract dates), you should use Sys.setlocale().
See ?Sys.setlocale for more details.
In order to see all available languages on a linux system, you can run
system("locale -a", intern = TRUE)
To permanently make it works, in both R and Rstudio (with Win 10),
one way to do this is to run the script every time automatically in the background initially.
No more changing the system language that influence the windows.
No more R only but fail in Rstudio. No more run a script every time manually. No more admin right but fail. No more short-cut setting but fail.
Step 1.
Use your system search, to find the file named "Rprofile"
My response is
C:\Program Files\R\R-4.0.5\library\base\R
C:\Program Files\R\R-4.0.5\etc
Step 2.
Edit C:\Program Files\R\R-4.0.5\library\base\R\Rprofile
The content:
This is the system Rprofile file. It is always run on startup.
Additional commands can be placed in site or user Rprofile files
(see ?Rprofile)
... and so on.
Step 3. Add Sys.setenv(LANGUAGE="en") at the end of the scrip
local({
Sys.setenv(LANGUAGE="en")
})
P.S. If you encounter the issue of authorization/saving,
move this file to desktop and replace the original file after editing.
type this first:
system("defaults write org.R-project.R force.LANG en_US.UTF-8")
then you will get a index number(in my case is 127)
then type:
Sys.setenv(LANG = "en")
then type the number and ENTER
127
For me worked:
Sys.setlocale("LC_MESSAGES", "en_US.utf8")
Testing:
> Sys.setlocale("LC_MESSAGES", "en_US.utf8")
[1] "en_US.utf8"
> x[3]
Error: object 'x' not found
Also working to get english messages:
Sys.setlocale("LC_MESSAGES", "C")
To reset to german messages I used
Sys.setlocale("LC_MESSAGES", "de_DE.utf8")
Here is the start of my sessionInfo:
> sessionInfo()
R version 3.4.1 (2017-06-30)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 16.04.2 LTS
A simple solution would be setting export Lang=C in your bash script.
I had a similar issue where the default language was german so it reverted back to english.
If you want to change R's language in terminal to English forever, this works fine for me in macOS:
Open terminal.app, and say:
touch .bash_profile
Then say:
open -a TextEdit.app .bash_profile
These two commands will help you open ".bash_profile" file in TextEdit.
Add this to ".bash_profile" file:
export LANG=en_US.UTF-8
Then save the file, reopen terminal and type R, you will find it's language has changed to english.
If you want language come back to it's original, just simply add a # before export LANG=en_US.UTF-8.
The only thing that worked for me was uninstalling R entirely (make sure to remove it from the Programs files as well), and install it, but unselect Message Translations during the installation process. When I installed R, and subsequently RCmdr, it finally came up in English.
In Ubuntu 14.04 LTS I had to remove the # from the comment #LANGUAGE=EN.
All other options din not work for me.
Change your current regional format to a different regional format in region settings on time&language settings in Windows by clicking on your time/date in lower right corner > adjust time/date > Region > change regional format to UK or US
This worked for me with a windows 10 laptop in German, where I wanted i.e. lubridate to return dates in English:
Sys.setlocale("LC_TIME", "English")
Im using R Studio on a Mac and I couldn't find the Rconsole file. So I took a more brutal way and just deleted the unwanted language files from the R app.
You just have to go to your Rapp in your application Folder, right click, show package content then /contents/Resources/. There are the language files e.g. English.lproj or in my case de.lproj wich I deleted. After restarting R, error messages appear in English..
Maybe thats helpful!
you simply have to change the basic language of microsoft on your computer!
press the windows button together with r, and tip the following code into the window that is opened
control.exe /name Microsoft.Language
load the language package you want to use and change the options. but take care, this will change also your keyboard layout!
on windows, when you have no admin right, just create a new program shortcut to Rgui.exe. Then in the properties of that shortcut, go to the 'Shortcut' tab and modify the target to include the system language of your choice, e.g. "C:\Program Files\R\R-3.5.3\bin\x64\Rgui.exe" LANGUAGE=en

Strange locale problems in RStudio after update to OsX Mojave

I'm having strange problems with R after updating to OsX Mojave.
When I start up a RStudio project I get:
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"
Than, if I source() R files raise an error if I don't remove the encoding = 'UTF-8' option if there are non-english characters like accented vowels.
Finally, the same characters if I use the View function get encoded, so àèòù become <c3><a0><c3><a8><c3><b2><c3><b9>
How can I solve this? it's pretty annoying expecially when save/sourcing R files from RStudio, since it puts encoding = 'UTF-8' by default.
UPDATE: the problem seems to be RStudio specific. Using plain R I don't get any errors.
The same problem appears on my laptop too.
However, it is not the first time that r-studio locale kinks after new MAC OS release.
How to fix 'tar: Failed to set default locale' error?
The link above, which was created 8 years ago, solved this problem with one line of code:
system('defaults write org.R-project.R force.LANG en_US.UTF-8')
Also I found your related github issue. Seems a new update of r-studio fixed this problem.
Either an update or running the code above will help.
https://github.com/rstudio/rstudio/issues/3587

Setting locale failed

I keep getting the following error message in the R Markdown log:
cropping document_files/figure-latex/ranking_time_output-1.pdf
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LC_ALL = (unset),
LC_CTYPE = "en_NL.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").
I've tried numerous things, such as:
Sys.setlocale("LC_ALL", 'en_US.UTF-8')
Sys.setenv(LANG = "en_US.UTF-8")
Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8')
running in R. However, non of this seems to work.
Do I have to do something in the command line or is it an issue that I can fix in R? I'm not an expert in both, so would appreciate help!
RStudio version: 0.99.903, system: Mac OS X 10_11_6
Furthermore I'm located in the Netherlands, but I run everything on my system in English.
LC_CTYPE is set to "en_NL.UTF-8". Such a locale does not exist on Mac OS X (and probably no other OS). Try to find where the wrong setting comes from because it will probably cause other problems, too.
Setting the locale with Sys.setlocale() is useless because Perl is running in a child process created with fork() and exec() and then switches locale based on the process environment.
Setting the environment for the Perl process is probably the right approach but you have to overwrite the erroneous value LC_CTYPE, not LC_ALL:
Sys.setenv(LC_CTYPE = "en_US.UTF-8")
You can set those environment vars by:
sudo vi /etc/environment
add these lines
LANG=en_US.utf-8
LC_ALL=en_US.utf-8

Changed locale in R. Reset failes

OS X 10.9.2 + R 3.0.2 and R 3.1.0
I have set the locale in R with
Sys.setlocale(category = "LC_TIME", locale = "C")
because I wanted English weekday names in my plots. (LC_TIME locale was "de_DE.UTF-8")
This worked, but the change has become permanent. Restarting R gives:
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
..
5: Setting LC_MONETARY failed, using "C"
I tried to reset the locale with these commands:
Sys.setlocale(category = "LC_TIME", locale = "")
Sys.setlocale(category = "LC_ALL", locale = "")
In both cases I got a warning:
..
OS reports request to set locale to "" cannot be honored
I also did reinstall R (in combination with an upgrade from R 3.0.2 to R 3.1.0
Nothing changed. May be the locale settings are stored in a dot-file, which is kept when upgrading, but I can't find where.
So if nobody knows a working reset command, an idea in which file the locale setting is stored may suffice.
Enforcing the language setting with
system("defaults write org.R-project.R force.LANG de_DE.UTF-8")
or
system("defaults write org.R-project.R force.LANG en_US.UTF-8")
plus restart fixed R on my computer. (I tested both settings.)
R starts now without error
The setting is permanent. I.e. I can quit and restart R and the setting "survives".
The Sys.setlocale(..) command sets the locale temporarily
The reset with Sys.setlocale(.., locale = "") works now!
Information on enforcing the language setting can be found in
R -- Help -- R for Mac OS X FAQ -- 7 Internationalization of the R.app:
If you use a non-standard setup .. you can override the auto-detection ...
Unclear is if it really was the Sys.setlocale() command that corrupted my system, or if it was something I did later. And unclear is if there is a way to reset the system to the original state. That would be in my eyes a more natural solution than enforcing the language setting.
The OP has promised to post a more complete answer but it should be noted that it was in the R-for-MAC-FAQ
7 Internationalization of the R.app

Resources