torsdag 5 maj 2011

The missing setup for Mac

This one should have been included by default. I you, like me, still like the old tools best and think power is king, you'll soon discover that Apple has a not provided all the glue needed to fit the two worlds together nicely. All text in OS X should be UTF-8, right? So, how come for instance an R session started within ESS of Aquamacs provides garbled text for non-ascii characters then?

Well, the problem lies in the old LANG environment variable. R expects it provide it with the LOCALE settings to use, and within an Aquamacs/ESS session, you'll get this:

Sys.getenv('LANG')
LANG

""

which means that the session will use the default "C" locale (I think). Not very useful for UTF-8 text, as you'll get lots of funny looking double characters.

The solution is to do this in your terminal:

defaults write ~/.MacOSX/environment LANG sv_SE.UTF-8
defaults write ~/.MacOSX/environment LC_ALL sv_SE.UTF-8

(for instance, for Swedish locale and UTF-8 encoding) and re-login. (Log out and log in again)
This will push the same settings to R and Aquamacs, and the settings will stay. Nice! Finally we can all start using Emacs again :-)

Inga kommentarer:

Skicka en kommentar