R Studio不适合使用汉字 [英] R Studio does not work with Chinese Characters properly

查看:162
本文介绍了R Studio不适合使用汉字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的R Studio中似乎有与汉字一起工作的问题。
一个简单的代码如下:

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"

即使我运行

Sys.setlocale(category="LC_ALL",locale="chinese")*

我的Windows笔记本电脑和Mac都发生这种情况。

This happened to both my Windows laptop and Mac.

任何人都可以告诉我如何配置R Studio以读取数据中文适当吗

Can anyone tell me how to configure the R Studio in order to read the data in Chinese properly?

推荐答案

在Shell R中运行

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"

在RStudio中运行

Run in RStudio

> print("中文")
[1] "\344\270\255\346\226\207"
> Sys.getlocale()
[1] "C"

相比之下,你可以找到RStudio中的区域环境未设置为支持UTF-8。

By contrast, you can find the locale environment in RStudio is not set to support UTF-8.

在RStudio运行时,不应更改区域环境,您可以在.Rprofile中调用Sys.setlocale 。 (OS X可以。)

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")

您可以在R帮助中找到更多信息?启动 RStudio字符编码

You can find more information in R help ?Startup and RStudio Character Encoding

这篇关于R Studio不适合使用汉字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆