做中文文本挖掘的时候经常要读取中文网站上的信息,但英文系统RStudio在WINDOWS系统下有无法完全兼容中文字符,所以print到显示器上的中文字符统统是乱码。处理方法如下:
首先修改系统语言:
- Control Panel -> Region and Language -> Formats -> Chinese (Simplified, PRC)
- Control Panel -> Region and Language -> Administrative -> Change System Locale... -> Chinese (Simplified, PRC)
修改完了以后,可以用`sessionInfo()`在RStudio中查看系统设置:
sessionInfo()
R version 3.1.2 (2014-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
locale:
[1] LC_COLLATE=Chinese (Simplified)_People's Republic of China.936
[2] LC_CTYPE=Chinese (Simplified)_People's Republic of China.936
[3] LC_MONETARY=Chinese (Simplified)_People's Republic of China.936
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_People's Republic of China.936
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] lubridate_1.3.3 tmcn_0.1-3
loaded via a namespace (and not attached):
[1] bitops_1.0-6 digest_0.6.8 httr_0.6.1 memoise_0.2.1
[5] plyr_1.8.1 Rcpp_0.11.3 RCurl_1.95-4.5 Rwordseg_0.2-1
[9] stringr_0.6.2 swirl_2.2.21 testthat_0.9.1 tools_3.1.2
[13] yaml_2.1.13
可以看到
然后修改RStudio中的读取和保存,还有默认编辑的encoding设置——统统修改为UTF-8:- File -> Reopen with Encoding -> UTF-8
- File -> Save with Encoding -> UTF-8
- Tools -> Global -> General -> Default text encoding -> UTF-8
唯一的不太习惯的地方就是所有的error message或者warning message都会变得有点莫名其妙。。。
library(dfsaf)
Error in library(dfsaf) : 不存在叫‘dfsaf’这个名字的程辑包
如果没有心理洁癖,这样将就还是可以的。。。
版权声明:本文为u013889309原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。