How to Change Language Settings in R

How to change language settings in R

You can set this using the Sys.setenv() function. My R session defaults to English, so I'll set it to French and then back again:

> Sys.setenv(LANG = "fr")
> 2 + x
Erreur : objet 'x' introuvable
> Sys.setenv(LANG = "en")
> 2 + x
Error: object 'x' not found

A list of the abbreviations can be found here.

Sys.getenv() gives you a list of all the environment variables that are set.

The R console is in my native language, how can I set R to English?

On a fresh install, adding language = en to the Rconsole file (which exists by default under R_HOME\etc) will make R's language English in the R console as well as RStudio. This can be overridden by code in the working directory and RStudio's individual projects.

How to get RStudio to use R language settings?

A workaround that works only if you want English, is to suppress the translation files.

An easy way to proceed is to uninstall R and then reinstall R without the translation files. So be sure to chose customize installation and to unselect the translation files during installation.

How do I set R console's language to English using a configuration file?

Does my current ~/.Renviron achieve this goal?

Probably yes, but potentially not quite.

The relevant information can be found in the locales documentation:

The following categories should always be supported: "LC_ALL", "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", "LC_NUMERIC" and "LC_TIME". Some systems (not Windows) will also support "LC_MESSAGES", "LC_PAPER" and "LC_MEASUREMENT". […]

Note that setting category "LC_ALL" sets only categories "LC_COLLATE", "LC_CTYPE", "LC_MONETARY" and "LC_TIME". […]

Note that the LANGUAGE environment variable has precedence over "LC_MESSAGES" in selecting the language for message translation on most R platforms.

So you might want to also set those categories not set by LC_ALL or LANGUAGE:

  • LC_NUMERIC
  • LC_PAPER
  • LC_MEASUREMENT

Lastly, the R “Startup” documentation tells us that using ~/.Renviron is a good place to set these:

Unless --no-environ was given on the command line, R searches for site and user files to process for setting environment variables. […] The name of the user file can be specified by the R_ENVIRON_USER environment variable; if this is unset, the files searched for are ‘.Renviron’ in the current or in the user's home directory (in that order).

Personally I prefer de-cluttering my home directory and putting all such configuration under ~/.config, e.g. ~/.config/R/REnviron. Doing so requires slightly more work, however, since R by default doesn’t respect the XDG conventions: to fix this I’m setting the environment variables R_ENVIRON_USER, R_LIBS_USER and R_PROFILE_USER in my .bashrc:

export R_ENVIRON_USER=$HOME/.config/R/Renviron

# Need to be set here rather than in REnviron so that they can be overridden
# temporarily:

export R_PROFILE_USER=${XDG_CONFIG_HOME-$HOME/.config}/R/init.r
export R_LIBS_USER=${XDG_DATA_HOME-$HOME/.local/share}/R/x86_64-pc-linux-gnu-library/%v

Default language of R

There are several questions dealing with that problem:

- How to change language settings in R

- The R console is in my native language, how can I set R to English?

Type locale in the terminal and check your language settings. If you want everything to be in US english, it should look like this

locale 

LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL="en_US.UTF-8"

In your case, I assume that it is a mix of en_US.UTF-8 and your local russian language setting.

These variables are set system wide by your language & region settings. However, you can also set them in your ~/.bash_profile. For example, I use the following settings:

# language settings
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8

Restart R/RStudio and everything should work.



Related Topics



Leave a reply



Submit