Change locale in RStudio on Windows

Hi everyone,

according to this article https://support.posit.co/hc/en-us/articles/200532197-Character-Encoding-in-the-RStudio-IDE
we should only use Sys.setlocale in .RProfile to avoid issues.

Does anyone have a suggestion how to do this efficiently if scripts are used on a number of workplaces or sent around? It seems pretty cumbersome to me to ask every user to edit his or her .RProfile file before using the scripts. Adding it to a script would be a lot easier for ensuring scripts are executed the same on all workplaces. Does anyone know what these issues are the article refers to?

Thank you for your help

Hi @snowman
Welcome to the Community Forum.

The output from help("Sys.setlocale") discusses some of the complexity and issues of changing the locale that R and RStudio are operating under. The language setting on each machine will ensure that output, error and warning messages are translated into the "local" language (see Sys.getenv()). Are there other specific differences that you expect between the different locations (e.g. input data format, names of days, names of months)? One obvious difference is timezone but this is also detected from OS settings (see help(timezones)).

You could bundle your script(s) into an RStudio project with its own .RProfile file to adjust the locale settings that would apply only for that limited R session.

Hi @DavoWW
Thank you for your reply.

I am mostly concerned with character encoding. Input data, scripts and script names contain non ASCII characters. Input data encoding can be selected in read.csv or similar functions, scripts with source(..., encoding = ...), but I get an error when script names contain non ASCII characters and are read in with source. The reason (from what my limited technical understanding is) seems to be that these scripts are saved as UTF8 files, but some systems use windows-1252 on their OS, which is then taken over by R. That is why I have Sys.setlocale("LC_ALL", ".utf8") in my .RProfile as then all my scripts are sourced without problems. But this requires such a file be set up on all machines.

Setting up a project .RProfile file seems like a good idea to me, though. I think this would remedy this situation.