utils::read.csv()仍然不能自动识别GBK编码的中文文件。这对于新手来说是个障碍,影响他们成功读取数据。如果这个问题能够得到解决就好了。 shunwang
utils::read.csv("测试中文ansi.csv")
Error in make.names(col.names, unique = TRUE) :
'<d6><d0><ce><c4>'多字节字符串有错误
utils::read.csv("测试中文utf8.csv")
X 中文1 中文2
1 1 中文a 中文a
2 2 中文b 中文b
utils::read.csv("测试中文utf8在excel里面修改过.csv")
Error in make.names(col.names, unique = TRUE) :
'<d6><d0><ce><c4>'多字节字符串有错误
read.csv <- function(...) {
fun <- function(x) utils::read.csv(..., fileEncoding = "GB18030")
tryCatch(utils::read.csv(..., fileEncoding = "UTF-8"), warning = fun, error = fun)
}
read.csv("测试中文ansi.csv")
X 中文1 中文2
1 1 中文a 中文a
2 2 中文b 中文b
read.csv("测试中文utf8.csv")
X 中文1 中文2
1 1 中文a 中文a
2 2 中文b 中文b
read.csv("测试中文utf8在excel里面修改过.csv")
X 中文1 中文2
1 1 中文a 中文a
2 2 中文b 中文b
在excel里自动修改过的表格
1 NA
2 NA
R.version
_
platform x86_64-w64-mingw32
arch x86_64
os mingw32
crt ucrt
system x86_64, mingw32
status Under development (unstable)
major 4
minor 4.0
year 2024
month 02
day 28
svn rev 85999
language R
version.string R Under development (unstable) (2024-02-28 r85999 ucrt)
nickname Unsuffered Consequences