1

I keep getting the following error message in the R Markdown log:

cropping document_files/figure-latex/ranking_time_output-1.pdf
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
    LC_ALL = (unset),
    LC_CTYPE = "en_NL.UTF-8",
    LANG = "en_US.UTF-8"
    are supported and installed on your system.
perl: warning: Falling back to the standard locale ("C").

I've tried numerous things, such as:

Sys.setlocale("LC_ALL", 'en_US.UTF-8')
Sys.setenv(LANG = "en_US.UTF-8")
Sys.setlocale("LC_MESSAGES", 'en_GB.UTF-8')

running in R. However, non of this seems to work.

Do I have to do something in the command line or is it an issue that I can fix in R? I'm not an expert in both, so would appreciate help!

RStudio version: 0.99.903, system: Mac OS X 10_11_6

Furthermore I'm located in the Netherlands, but I run everything on my system in English.

Jaap
  • 81,064
  • 34
  • 182
  • 193
sander
  • 141
  • 2
  • 7
  • Try running `sudo locale-gen en_US.UTF-8` on your machine. Which distro are you using BTW? You could also add following in your `.bashrc` file. `export LANGUAGE=en_US.UTF-8 export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LC_TYPE=en_US.UTF-8` – Chankey Pathak Sep 16 '16 at 08:02
  • I get the following error when I run your command: sudo: locale-gen: command not found. Where can I find my distro? – sander Sep 16 '16 at 08:20
  • I've added the lines in my .bashrc file, but it did'nt change anything. Unfortunately I still get the errors. – sander Sep 16 '16 at 08:29
  • Did you open a new terminal after making changes in `~/.bashrc`? – Chankey Pathak Sep 16 '16 at 08:35
  • Yes I've rebooted my computer. – sander Sep 16 '16 at 08:44
  • When I run 'locale' I notice that LC_ALL is missing. How do I change this? I've tried multiple suggested solutions found elsewhere, but they all give the following errors: ```sudo: apt-get: command not found```, ```sudo: aptitude: command not found```, ```sudo: dpkg-reconfigure: command not found``` – sander Sep 16 '16 at 09:06
  • Try adding `LC_ALL` to `/etc/profile` using root. This way all users will get this setting. Not sure whether it would help or not. – Chankey Pathak Sep 16 '16 at 09:08
  • This has nothing to do with Perl. For example, running `locale` will give you a similar error message. Your system doesn't recognize the locale, meaning there's currently no locale by that name on your system. – ikegami Sep 16 '16 at 15:17
  • Related post: https://stackoverflow.com/questions/49089099/perl-fails-to-set-locale-even-though-it-is-installed – Khoi Ngo Apr 06 '22 at 10:01

2 Answers2

3

You can set those environment vars by:

sudo vi /etc/environment

add these lines

LANG=en_US.utf-8
LC_ALL=en_US.utf-8
Yakir GIladi Edry
  • 2,511
  • 2
  • 17
  • 16
0

LC_CTYPE is set to "en_NL.UTF-8". Such a locale does not exist on Mac OS X (and probably no other OS). Try to find where the wrong setting comes from because it will probably cause other problems, too.

Setting the locale with Sys.setlocale() is useless because Perl is running in a child process created with fork() and exec() and then switches locale based on the process environment.

Setting the environment for the Perl process is probably the right approach but you have to overwrite the erroneous value LC_CTYPE, not LC_ALL:

Sys.setenv(LC_CTYPE = "en_US.UTF-8")
Guido Flohr
  • 1,871
  • 15
  • 28