r 控制台中汉字输出问题,r 版本 4 [英] Output problem with Chinese characters in r console, r version 4

查看:56
本文介绍了r 控制台中汉字输出问题,r 版本 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<块引用>

更新到 r 版本 4 后,在 r 控制台中以 Unicode 显示中文字符的输出.我的问题是如何让它正确显示汉字.

<块引用>

在我的旧版本 r 3.6.1 中,它与以下语言环境完美配合:

<代码>>会话信息()R 版本 3.6.1 (2019-07-05)平台:x86_64-apple-darwin15.6.0(64 位)运行于:macOS 10.16矩阵产品:默认BLAS:/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylibLAPACK:/Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib语言环境:[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8附带的基础包:[1] stats graphics grDevices utils datasets 方法基础通过命名空间加载(而不是附加):[1] 编译器_3.6.1>打印(我")[1] 我"

<块引用>

但是,使用更新的 r,它无法正确打印字符.我按照网上的解决方案,尝试更改语言环境,但没有解决问题.

R 版本 4.0.4 (2021-02-15)平台:x86_64-apple-darwin15.6.0(64 位)运行于:macOS Catalina 10.15.7矩阵产品:默认BLAS:/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylibLAPACK:/Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib语言环境:[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8附带的基础包:[1] stats graphics grDevices utils datasets 方法基础通过命名空间加载(而不是附加):[1] 编译器_4.0.4>打印(我")[1]\u6211">Sys.setlocale(category = "LC_ALL", locale = "chs")[1] 《》警告信息:在 Sys.setlocale(category = "LC_ALL", locale = "chs") 中:操作系统报告将区域设置设置为chs"的请求;不能被尊重>sys.setlocale(category = "LC_ALL", locale = "zh_CN.utf-8")[1] 《zh_CN.utf-8/zh_CN.utf-8/zh_CN.utf-8/C/zh_CN.utf-8/en_US.UTF-8》>打印(我")[1]\u6211"

我怀疑这不是语言环境问题,因为在旧版 r 中,语言环境与新版本相同,但显示字符没有问题.

有人会帮忙吗?真的很感谢!

解决方案

我在使用 R 4.0.4 时也遇到了同样的问题.这是一个已报告给 R 团队的错误.该错误应该在下一个 R 版本中修复,所以我回滚到 R 4.0.3.

更多详情,请参考这篇文章:

在 R 4.0.4 上打印()多字节字符的问题

After updated to r version 4, the output of Chinese characters were displayed in Unicode in r console. My questions is how to let it properly display the Chinese character.

In my older version, r 3.6.1, it worked perfectly with the following locale:

> sessionInfo()
R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_3.6.1

> print("我")
[1] "我"

However, using the updated r, it cannot print the Character properly. I followed the solutions on the internet and tried to change the locale but did not solve the problem.

R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Catalina 10.15.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

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

loaded via a namespace (and not attached):
[1] compiler_4.0.4

> print("我")
[1] "\u6211"


> Sys.setlocale(category = "LC_ALL", locale = "chs") 
[1] ""
Warning message:
In Sys.setlocale(category = "LC_ALL", locale = "chs") :
  OS reports request to set locale to "chs" cannot be honored



> Sys.setlocale(category = "LC_ALL", locale = "zh_CN.utf-8")
[1] "zh_CN.utf-8/zh_CN.utf-8/zh_CN.utf-8/C/zh_CN.utf-8/en_US.UTF-8"
> print("我")
[1] "\u6211"

I suspect that this is not a problem due to the locale issue, since in the older r version, the locale was the same as the new version, but it had no problem displaying the characters.

Would any one help with that? Really appreciated!

解决方案

I also run into the same problem using R 4.0.4. And this is a bug which has been reported to R team. The bug is supposed to be fixed in the next R release so I roll back to R 4.0.3.

For more details, please refer to this post:

issue with print()ing multibyte characters on R 4.0.4

这篇关于r 控制台中汉字输出问题,r 版本 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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