Why is my ESS R session falling back to C language?
I'm on OSX Yosemite running Emacs 24.5 and R 3.2
I have this in my ~ / .bash_profile:
export LANG=en_US.UTF-8
export LANGUAGE=en_US:en
export LC_CTYPE="en_US.UTF-8"
export LC_NUMERIC="en_US.UTF-8"
export LC_TIME="en_US.UTF-8"
export LC_COLLATE="en_US.UTF-8"
export LC_MONETARY="en_US.UTF-8"
export LC_MESSAGES="en_US.UTF-8"
export LC_PAPER="en_US.UTF-8"
export LC_NAME="en_US.UTF-8"
export LC_ADDRESS="en_US.UTF-8"
export LC_TELEPHONE="en_US.UTF-8"
export LC_MEASUREMENT="en_US.UTF-8"
export LC_IDENTIFICATION="en_US.UTF-8"
export LC_ALL=en_US.UTF-8
this is in emacs settings:
(setq current-language-environment "UTF-8")
(add-hook 'ess-R-post-run-hook
(lambda () (set-buffer-process-coding-system
'utf-8-nfd-unix 'utf-8-nfd-unix)))
And I even set the following system-wide:
defaults write org.R-project.R force.LANG en_US.UTF-8
When I run R from the command line or in RStudio, it uses the correct locale. However, when I start the R process in emacs, I get the following warning:
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"
And any non-ASCII characters are generated by errors. How do I set the correct language?
source to share
So, the problem isn't Emacs, ESS, or R, it's that OSX processes launched by startup don't inherit any environment variables in .profile, .bash_profile, or .bashrc. Instead, you need to install the environment via launchd.
By doing this problem, I solved:
/bin/launchctl setenv LANG en_US.UTF-8 /bin/launchctl setenv LC_ALL en_US.UTF-8 /bin/launchctl setenv LC_CTYPE en_US.UTF-8 /bin/launchctl setenv LC_COLLATE en_US.UTF-8 /bin/launchctl setenv LC_MESSAGES en_US.UTF-8 /bin/launchctl setenv LC_TIME en_US.UTF-8 /bin/launchctl setenv LC_MONETARY en_US.UTF-8
To preserve environment variables across reboots, add an entry to / Library / LaunchDaemons / (OSX> 10.9). For earlier versions, add it to /etc/launchd.conf instead .
The above options will be set for all processes started by launch. If this is not desired, you can edit the Info.plist file in a separate .app file and set the variables as key values in the key fileLSEnvironment
For example, to solve the problem in Emacs, I edited the file:
/usr/local/Cellar/emacs/24.5/Emacs.app/Contents/Info.plist
Adding the following entry to the top-level file:
<key>LSEnvironment</key>
<dict>
<key>LANG</key>
<string>en_US.UTF-8</string>
<key>LC_ALL</key>
<string>en_US.UTF-8</string>
<key>LC_CTYPE</key>
<string>en_US.UTF-8</string>
<key>LC_COLLATE</key>
<string>en_US.UTF-8</string>
<key>LC_PAPER</key>
<string>en_US.UTF-8</string>
<key>LC_ADDRESS</key>
<string>en_US.UTF-8</string>
<key>LC_MONETARY</key>
<string>en_US.UTF-8</string>
<key>LC_NUMERIC</key>
<string>en_US.UTF-8</string>
<key>LC_TELEPHONE</key>
<string>en_US.UTF-8</string>
<key>LC_MESSAGES</key>
<string>en_US.UTF-8</string>
<key>LC_IDENTIFICATION</key>
<string>en_US.UTF-8</string>
<key>LC_MEASUREMENT</key>
<string>en_US.UTF-8</string>
<key>LC_TIME</key>
<string>en_US.UTF-8</string>
<key>LC_NAME</key>
<string>en_US.UTF-8</string>
</dict>
(Of course, not all variables are strictly necessary)
source to share