Stack Exchange
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.

Lately there have been some changes in how R deals with languages/translations. This seems a problem related to the namespace of the translations, if you can manage to make a reproducible example I think this is a bug in R. (Michael Chirico or Michael Lawrence might know more about the translation and their namespaces)

@llrs Thanks, that’s interesting. The fact that not one but two languages are used in the message makes it likely that there’s a bug somewhere. Unfortunately I have no idea how to reproduce this on a different system, since I am specifically not touching my configuration. The “minimal reproducible example” in this case, appears to be the entire OS installation (not really, of course, but I have no idea which part of it is causing this).

You could try to check whether it this reproducible outside your computer in another MacOS (or OS). That would be enough probably for them to try to find out more. Which LANG do you have? In the env | grep 'LANG\|LC' output there is none? I see it on my computer but this might be just a difference between Ubuntu and MacOS

@llrs Unless I specifically set it myself (e.g. in .zshrc), it’s unset.
