R version 3.5.1 (2018-07-02) -- "Feather Spray"
Copyright (C) 2018 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Also, I noticed you cross-posted this to StackOverflow:
In the event that you cross-post, we ask that you include the link to the other thread or issue so that there's no unnecessary duplication of effort, in the event that it gets resolved over there.
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:
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.
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: https://github.com/rstudio/rstudio/issues/3587
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").
Hey @bakaburg1, that sounds like a tough problem 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 Not sure whether it'll help you if your problem is isolated to RStudio, but
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 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.