Set locale to system default UTF-8

后端 未结 3 2103
盖世英雄少女心
盖世英雄少女心 2020-11-28 10:15

When running R inside rApache, the locale is inherited from the Apache webserver, and therefore Sys.getlocale() is always equal to \"C\". I would l

3条回答
  •  时光说笑
    2020-11-28 11:04

    Answering my own question: On Ubuntu the default LANG is defined in /etc/default/locale:

    jeroen@dev:~⟫ cat /etc/default/locale
    # Created by cloud-init v. 0.7.7 on Wed, 29 Jun 2016 11:02:51 +0000
    LANG="en_US.UTF-8"
    

    So in R we could do something like:

    readRenviron("/etc/default/locale")
    LANG <- Sys.getenv("LANG")
    if(nchar(LANG))
       Sys.setlocale("LC_ALL", LANG)
    

    Apache also has a line in /etc/apache2/envvars that can be uncommented to enable this.

提交回复
热议问题