Skip to navigation

Umlaut in R plot on Mac using ESS in Emacs (Aquamacs)

To get the umlaut in your Emacs buffer, type C-x 8 " then the appropriate letter. For example, to get “ü”, type:

C-x 8 " u

In a plot label, this then did not show up correctly, but instead displayed as a a dot.
The problem was that R was thinking it was working in a North American locale:

> Sys.getlocale()
[1] "C"

Set this to the UTF-8 encoding in a UK environment:

Sys.setlocale("LC_ALL", "en_GB.UTF-8")

This did not work:

plot(1:10,1:10,main="Ɯberlegung")
Error: invalid multibyte character in parser at line 1

I had to tell Emacs (Aquamacs) to use UTF-8 encoding for the R process buffer:

M-x set-buffer-process-coding-system

Emacs will ask you for the coding-system for the output and input process, just type

utf-8

and hit ENTER.

To make these changes permanent:

  1. To your ~/.Rprofile file, add the following line:
    invisible(Sys.setlocale("LC_ALL", "en_GB.UTF-8"))

    Wrapping in invisible() is of course not necessary but avoid printing the output to the buffer.

  2. To your ~/.emacs file, add the following:
    (custom-set-variables
    '(current-language-environment "UTF-8"))

    (Or add the line to your custom-set-variables section.)

Addendum

Generally, you can get exhaustive info on the currently used encoding system with the Emacs command:

M-x describe-coding-system

Comments are closed.