Strange locale problems in R after update to Mojave


I'm sorry for the cross-posting; at the beginning I didn't realize it was a RStudio specific problem, but then I noticed that plain R doesn't suffer from it, so I created an issue in github problem because it looked like a bug to me.

In github they noticed from a RStudio diagnostic report that I provided that in the locale setting there was an impossible locale:

[1] "en_IT.UTF-8"

[1] "en_IT.UTF-8"

en_IT doesn't make sense because it would mean an italian version of english. In fact those options are not present in my machine locales (fetched by locale -a on terminal).

The problem is confirmed running Sys.getenv()

LANG                                           en_IT.UTF-8
LC_CTYPE                                       en_IT.UTF-8

I don't really know where these setting come from.

The workaround to make everything work is using Sys.setlocale(locale = 'en_US.UTF-8'). But I think it's a problem of RStudio interacting with Mojave.

Thanks to @phahn who gave me a useful hint.


If you could post a link to the issue here as well that would be great. It will allow anyone in the future to see whether the issue has been closed, which will help them figure out if they're facing the same problem!



Here's the issue:
but they closed it because I already wrote here. I don't really agree with closing it, because the issue is real and is not solved; I just found a (not very elegant) workaround (which I posted both here and on github).



using WriteXLS::WriteXLS() raises an error even after resetting locale with Sys.setlocale(locale = 'en_US.UTF-8')

perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
	LC_ALL = (unset),
	LC_CTYPE = "en_IT.UTF-8",
	LANG = "en_IT.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

Had to output the file using Vanilla R

This is getting annoying...


Hey @bakaburg1, that sounds like a tough problem :weary: This might be a basic check, but have you checked the Default text encoding option in RStudio's Tools > Global Options > Code > Saving? I would think this would only affect the encoding of files you save in RStudio, but I suppose it can't hurt to check!

EDIT: this support thread was the closest I could find to your problem :frowning: Not sure whether it'll help you if your problem is isolated to RStudio, but :confused:


I also encoutered a similar problem. After upgrading to Mojave, and even after clean-installing it,

  • the start message ("R is a free software...") appears in English, not in Japanese.
  • the following warning message appears
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"
  • I couldn't use Japanese characters on Rstudio.

With R-GUI and R running on a macOS terminal, everything is fine.


Sys.setlocale(category="LC_ALL", locale="ja_JP.UTF-8")

to my .Rprofile didn't solve the problem.

defaults write org.R-project.R force.LANG ja_JP.UTF-8

(at least seemingly) fixed it.


I tried defaults write org.R-project.R force.LANG en_US.UTF-8, and the error at the startup of R projects seems gone.

But I still see the same locale setting error when I render rmarkdown files. In one of such files I put Sys.setlocale() and I got C.


@hideaki: What do you see when you execute:

defaults read NSGlobalDomain AppleLocale

from a terminal? I suspect you're seeing something erroneous like en_JP? It seems like macOS Mojave is setting a strange locale here, and RStudio is inheriting that locale.


I'm getting it_IT, so it looks fine


What do you see when you execute:

defaults read NSGlobalDomain AppleLocale



Dang; thanks. That's not what I expected (I'm surprised that I see en_IT) but I'll see if I can learn more.


I noticed something else too.

I inserted Sys.setlocale(locale = 'en_US.UTF-8') into the rmarkdown file in the first code chunk. If I create a data.frame with special characters eg. df <- data.frame(a = 'aaèòà±é') in the first chunk, where I reset the locale, and then kable() it, I only get aa (that is the special characters get eliminated). If I create it in a subsequent chunk it prints ok.

So the locale reset seems to apply only to subsequent chunks, not to the one in which is done.


Sorry I didn't see the post. In the setting there is [Ask]. The defaults write org.R-project.R force.LANG en_US.UTF-8 trick seems to have solved the error when sourcing (or at least I believe so, since I'm not seeing it anymore, and I've touched so many things around that is hard to say what fixed it). But still I'm facing other locale problems here and there as written in the other posts.


Thank you for re-opening the GitHub issue and validating the problem.
I don't think en-IT is odd, if you've changed your macbook's region to Italy and keep setting English as a primary language.


Yes, you're right.

Regardless, there is a bug in Mojave where the locale is always reported with an en_ prefix, which RStudio was running afoul of.

This should hopefully be resolved in the latest daily builds (, with RStudio v1.2.1030. We'll plan on backporting the patch to v1.1 if we can confirm it does indeed function as expected.


But the odd locale is not in the list produced by running "locale -a" on terminal and the error is not present when running standalone R.
Another piece of information: when installing new packages I get this other warning: tar: Failed to set default locale. Again this warning do not appear in vanilla R.


Is that still happening with the latest daily build (as Kevin suggests it should be fixed in there, above).


Yep I confirm that the problem seems to be resolved after the update. Many thanks!


If your question's been answered (even if by you), would you mind choosing a solution? (See FAQ below for how).

Having questions checked as resolved makes it a bit easier to navigate the site visually and see which threads still need help.



Thanks all for this post !

I was hit by this problem a bit later so providing an update.

When I installed RStudio Desktop 1.1.463 the problem was solved.