如何在R中设置unicode语言环境?

如何在R中设置unicode语言环境?

问题描述:

我在UTF-8 .R文件中有一些特殊字符,并且尝试将代码作为文件在R命令行中运行会返回unexpected INCOMPLETE_STRING.

I have some special characters in my UTF-8 .R file and the attempt to run code as a file in the R command line returns unexpected INCOMPLETE_STRING.

同时,代码可以在RStudio或Eclipse中逐行运行.

Meanwhile, the code runs okay line by line, say, in RStudio or Eclipse.

我建议我需要通过Sys.setlocale(locale=)更改语言环境,但是我为UTF-8找到正确的locale参数的所有尝试(包括SO的回答)都给出了OS reports request to set locale to "UTF-8" cannot be honored.我可以设置Sys.setlocale(locale="English")之类的东西,但这无济于事.

I suggest I need to change the locale via Sys.setlocale(locale=), but all my attempts (including SO's answers) to find the right locale parameter for UTF-8 gave OS reports request to set locale to "UTF-8" cannot be honored. I can set up something like Sys.setlocale(locale="English"), but it doesn't help.

如何在Windows上设置"UTF-8"?

How to set up "UTF-8" on Windows?

我认为您无需将R的语言环境更改为UTF-8(

I don't think you need to change to locale of your R to UTF-8 (if that is even possible under windows)

source(..., locale="UTF-8")

应该可以解决问题.然后将R脚本翻译成您的本地语言环境.

should do the trick. The R-script is then translated into your local locale.