It seems that I have problem working with Chinese characters in my R Studio. A simple codes like the following:
data <- c("物品","方案")
data
# [1] "\347\211\251\345\223\201" "\346\226\271\346\241\210"
It remains the same even if I run
Sys.setlocale(category="LC_ALL",locale="chinese")*
This happened to both my Windows laptop and Mac.
Can anyone tell me how to configure the R Studio in order to read the data in Chinese properly?
Run in Shell R
> print("中文")
[1] "中文"
> Sys.getlocale()
[1] "en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8"
Run in RStudio
> print("中文")
[1] "\344\270\255\346\226\207"
> Sys.getlocale()
[1] "C"
By contrast, you can find the locale environment in RStudio is not set to support UTF-8.
You should not change the locale environment while RStudio is running, you can call Sys.setlocale in .Rprofile. (OS X is ok.)
$ cat ~/.Rprofile
Sys.setlocale(category="LC_ALL", locale = "en_US.UTF-8")
You can find more information in R help ?Startup
and RStudio Character Encoding
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With