Sys.setlocale(locale = foo)
默认使用 category = "LC_ALL"
;你可以为 R 进程的不同方面单独设置语言环境,例如:
locales <- c("LC_COLLATE","LC_CTYPE","LC_MONETARY","LC_NUMERIC","LC_TIME");
for (x in locales) { Sys.setlocale(category = x, locale="Japanese_Japan.65001")}
请遵守上面代码片段的所有警告
以及locales:查询或设置语言环境的方面文章中的其他注意事项:
- 尝试在会话期间更改字符集(通过
Sys.setlocale(“LC_CTYPE”,)
,如果这意味着不同的字符集)可能无法正常工作并可能导致一些混乱。
- 将
“LC_NUMERIC”
设置为除“C”
之外的任何值可能导致R表现异常,因此会给出警告。
- 自Windows以来,R本身使用的几乎所有输出例程忽略了“LC_NUMERIC”的设置,因为它们使用了未国际化的Trio库。
例如,我的语言环境是
捷克语,所以我尝试了上述代码片段(循环排列以按顺序查看结果和警告)。
Sys.getlocale(category = "LC_ALL")
Sys.setlocale(category = "LC_COLLATE" , locale="Czech_Czechia.65001")
Sys.setlocale(category = "LC_CTYPE" , locale="Czech_Czechia.65001")
Sys.setlocale(category = "LC_MONETARY", locale="Czech_Czechia.65001")
Sys.setlocale(category = "LC_NUMERIC" , locale="Czech_Czechia.65001")
Sys.setlocale(category = "LC_TIME" , locale="Czech_Czechia.65001")
Sys.getlocale(category = "LC_ALL")
输出(粘贴到RStudio控制台中):
> Sys.getlocale()
[1] "LC_COLLATE=Czech_Czechia.1250;LC_CTYPE=Czech_Czechia.1250;LC_MONETARY=Czech_Czechia.1250;LC_NUMERIC=C;LC_TIME=Czech_Czechia.1250"
> Sys.setlocale(category = "LC_COLLATE" , locale="Czech_Czechia.65001")
[1] "Czech_Czechia.65001"
> Sys.setlocale(category = "LC_CTYPE" , locale="Czech_Czechia.65001")
[1] ""
Warning message:
In Sys.setlocale(category = "LC_CTYPE", locale = "Czech_Czechia.65001") :
OS reports request to set locale to "Czech_Czechia.65001" cannot be honored
> Sys.setlocale(category = "LC_MONETARY", locale="Czech_Czechia.65001")
[1] "Czech_Czechia.65001"
> Sys.setlocale(category = "LC_NUMERIC" , locale="Czech_Czechia.65001")
[1] "Czech_Czechia.65001"
Warning message:
In Sys.setlocale(category = "LC_NUMERIC", locale = "Czech_Czechia.65001") :
setting 'LC_NUMERIC' may cause R to function strangely
> Sys.setlocale(category = "LC_TIME" , locale="Czech_Czechia.65001")
[1] "Czech_Czechia.65001"
> Sys.getlocale(category = "LC_ALL")
[1] "LC_COLLATE=Czech_Czechia.65001;LC_CTYPE=Czech_Czechia.1250;LC_MONETARY=Czech_Czechia.65001;LC_NUMERIC=Czech_Czechia.65001;LC_TIME=Czech_Czechia.65001"
>