[R] Change of locale

Chel Hee Lee chl948 at mail.usask.ca
Mon Jan 12 07:19:36 CET 2015


Could anyone kindly guide me how to change locale?  Any advice would be 
greatly appreciated.   What I am trying to do is to see if messages are 
correctly in a given locale.  The environment variables are:

 > sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-pc-linux-gnu (64-bit)

locale:
  [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C
  [3] LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8
  [5] LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8
  [7] LC_PAPER=en_CA.UTF-8       LC_NAME=C
  [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

* Since I do not create any objects yet, the following message must be 
shown when typing the alphabet 'a'.

 > a
Error: object 'a' not found
 > Sys.getenv()[c("LANG", "LANGUAGE")]
             LANG         LANGUAGE
    "en_CA.UTF-8" "en_CA:en_US:en"
 > Sys.getlocale("LC_MESSAGES")
[1] "en_CA.UTF-8"
 >

I am happy with this result.  Now, I'd like to see messages in Chineses.

 > Sys.setlocale("LC_MESSAGES", "zh_CN.utf8")
[1] "zh_CN.utf8"
 > a
Error: object 'a' not found

The message is still shown in English; thus, I am changing the value of 
'LANGUAGE'.

 > Sys.setenv(LANGUAGE="zh_CN.utf8")
 > a
错误: 找不到对象'a'
 > Sys.getenv()[c("LANG", "LANGUAGE")]
          LANG      LANGUAGE
"en_CA.UTF-8"  "zh_CN.utf8"
 > Sys.getlocale("LC_MESSAGES")
[1] "zh_CN.utf8"
 >

Now, I'd like to use messages in English again.  At this time, I changed 
the value of LANGUAGE rather than LC_MESSAGES.

 > Sys.setenv(LANGUAGE="en_CA.utf8")
 > a
错误: 找不到对象'a'

I still see this message in Chinese so that I change 'LC_MESSAGES'.

 > Sys.setlocale("LC_MESSAGES", "en_CA.utf8")
[1] "en_CA.utf8"
 > a
Error: object 'a' not found
 > Sys.getenv()[c("LANG", "LANGUAGE")]
          LANG      LANGUAGE
"en_CA.UTF-8"  "en_CA.utf8"
 > Sys.getlocale("LC_MESSAGES")
[1] "en_CA.utf8"
 >

Thus, should I set the same value on both 'LANGUAGE' and 'LC_MESSAGES' 
in order to change messages in a given locale?   However, it is 
questionable.  Please see the following example (messages in Japanese):

 > Sys.setenv(LANGUAGE="ja_JP.utf8")
 > a
  エラー:  オブジェクト 'a' がありません
 > Sys.getenv()[c("LANG", "LANGUAGE")]
          LANG      LANGUAGE
"en_CA.UTF-8"  "ja_JP.utf8"
 > Sys.getlocale("LC_MESSAGES")
[1] "en_CA.utf8"
 >
 > Sys.setenv(LANGUAGE="en_CA.utf8")
 > a
  エラー:  オブジェクト 'a' がありません
 > Sys.getenv()[c("LANG", "LANGUAGE")]
          LANG      LANGUAGE
"en_CA.UTF-8"  "en_CA.utf8"
 > Sys.getlocale("LC_MESSAGES")
[1] "en_CA.utf8"
 > a
  エラー:  オブジェクト 'a' がありません
 >

Is this a bug?  Any advice would be greatly appreciated.

Chel Hee Lee



More information about the R-help mailing list