During startup - Warning message: Setting LC_CTYPE= failed on Windows

windows
warning
locale

#1

Hi, before I start: this is a cross posting of a related SO issue by someone else that also bugs me:

Of course I will update both issues in case of a solution.

So, whenever I launch R or RStudio (R 3.5.2 with latest RTools) on Windows 10, I am getting the warning:

During Startup - Warning message:
Setting LC_CTYPE = failed

There seem to be several solutions for Mac OS and also some for Ubuntu, but I haven't seen any on Windows. The warning is frustrating as it also appears during package installation, where it is converted into an error which is stopping the installation process.

The output for my locales is currently:

> Sys.getlocale()
[1] "LC_COLLATE=English_Germany.65001;LC_CTYPE=C;LC_MONETARY=English_Germany.65001;LC_NUMERIC=C;LC_TIME=English_Germany.65001"

Would appreciate any help/ideas to solve the problem.


#2

The best workaround I found for that issue is to set up a .Renviron file and overwrite the locales there.

How to set and modify the .Renviron file is described i.e. in the regarding chaper of the open book Efficient R Programming. Therefore, one needs just to copy the lines

user_renviron = path.expand(file.path("~", ".Renviron"))
file.edit(user_renviron) # open with another text editor if this fails

and afterwards edit the .Renviron file to change the locale. Note that regarding on the OS some locales won't exist and it might be non trivial to install them. However, the locale "C" should always exist. For me also "English_United States.1252" worked on Windows and I added the following lines (including a linebreak) to the .Renviron file

LC_COLLATE  = "English_United States.1252"
LC_CTYPE    = "English_United States.1252"
LC_MONETARY = "English_United States.1252"
LC_NUMERIC  = "English_United States.1252"
LC_TIME     = "English_United States.1252"


#3

When I was having problems with locales in R (I got bogged down in character encoding hell) I did not go in the .Renviron direction, but edited my .Rprofile file instead, and it worked - there may be multiple solutions to the issue.

My problem & solution is documented on Stack Overflow (this forum was very young back then...)

if (.Platform$OS.type == 'windows') {
  Sys.setlocale(category = 'LC_ALL','English_United States.1250')
} else {
  Sys.setlocale(category = 'LC_ALL','en_US.UTF-8')
}

#4

Thanks for posting this alternative. I agree that many ways are possible when trying to change the startup behavior. As no one came up with an alternative resolving the issue on system level, I just like to add a link to an RStudio blog post that explains the differences of alternative ways for changing the startup behavior and may guide future readers on which path to take. Understanding R‘s startup.


closed #5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.