【发布时间】:2017-09-25 20:33:56
【问题描述】:
我正在使用 fread 读取 R 中的文件
test.set = fread("file.csv", header=FALSE, fill=TRUE, blank.lines.skip=TRUE)
我的 csv 包含 6 列。此文件中的一行示例是
"2014-07-03 11:25:56","61073a09d113d3d3a2af6474c92e7d1e2f7e2855","Securenet Systems 电台播放列表更新","你的爱","Fred Hammond & Radical for Christ","50fcfb08424fe1e2c653a87a64ee92d7"
但是,当其中一个单元格内有逗号时,某些行会以特定方式格式化。例如,
"2014-07-03 11:25:59","37780f2e40f3af8752e0d66d50c9363279c55be6","Spotify","\"你好\", 他撒谎了","Red Box","b226ff30a0b83006e5e06582fbb0afd3"
产生一个错误
Expecting 6 cols, but line 5395818 contains text after processing all
cols. Try again with fill=TRUE. Another reason could be that fread's
logic in distinguishing one or more fields having embedded sep=','
and/or (unescaped) '\n' characters within unbalanced unescaped quotes
has failed. If quote='' doesn't help, please file an issue to figure
out if the logic could be improved.
如您所见,导致错误的值是“\”你好\“,他撒谎”,我希望 fread 将其读取为“你好,他撒谎”。不过,我不确定如何解决这个问题 - 我已尝试按照建议使用 fill=TRUE 和 quote="" ,但错误仍然不断出现。这可能只是为 fread 找到正确参数的问题;有人知道那些可能是什么吗?
【问题讨论】:
-
read.csv(..., allowEscapes = TRUE) -
我知道这适用于 read.csv,但 fread 有类似的东西吗?我正在读取一个多千兆字节的文件,所以我更愿意使用 fread
-
fread文档中没有任何内容表明存在...
标签: r csv data.table