【问题标题】:How to keep UTF -8 encoding when using read csv in R?在 R 中使用读取 csv 时如何保持 UTF -8 编码?
【发布时间】:2020-07-05 19:17:16
【问题描述】:

我在使用时遇到了文件编码UTF-8丢失的问题

read.csv

在R中。这导致例如拉丁字母替换为不需要的符号,例如:Iguaçu。

我尝试使用以下 FileEncoding 参数:

read.csv(xx.csv, fileEncoding = 'UTF-8')
read.csv2(xx.csv, fileEncoding = 'UTF-8')

但出现错误:

Warning messages:1: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  invalid input found on input connection 'C:/xxx.csv'
2: In read.table(file = file, header = header, sep = sep, quote = quote,  :
  incomplete final line found by readTableHeader on 'C:/xxx.csv'

将csv读入R时保持UTF-8编码的解决方案是什么?

【问题讨论】:

  • 尝试使用Encoding = "UTF-8"而不是fileEncoding。

标签: r csv encoding utf-8 read.csv


【解决方案1】:

所以通过反复试验,我发现使用readr包中的函数

read_csv

而不是

read.csv
read.csv2

没有任何 fileEncoding 参数可以完成工作并且编码被保留。 希望这可能对某人有所帮助。

【讨论】:

  • 你应该提到 read_csv 来自 readr 包。
猜你喜欢
  • 2019-12-27
  • 1970-01-01
  • 2018-06-13
  • 2016-02-22
  • 2015-03-04
  • 2021-02-10
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多