使用 fread 导入 csv 时出现“在字符串中嵌入 nul"错误 [英] 'Embedded nul in string' error when importing csv with fread
问题描述
我尝试使用 data.table::fread
导入一个大文件 (3.5G).
I have a large file (3.5G) that I'm trying to import using data.table::fread
.
它最初是从以文本形式打开并保存为 CSV 的 rpt 文件创建的.
It was originally created from an rpt file that was opened as text and saved as a CSV.
这适用于较小的文件(具有相同类型的数据-相同的列和所有文件.这个只是用于更长的时间范围和更广泛的覆盖范围).
This has worked fine with smaller files (of the same type of data-same columns and all. This one is just for a longer timeframe and wider reach).
当我尝试运行时
mydata <- fread("mycsv.csv")
我得到错误:
fread("mycsv.csv") 中的错误:在字符串中嵌入 nul:'y e a r '
Error in fread("mycsv.csv") : embedded nul in string: 'y e a r '
这是什么意思?
推荐答案
我们可以在命令行中删除空终止符,使用类似:
We can remove the null terminators on the command line using something like:
sed 's/\0//g' mycsv.csv > mycsv.csv
或者正如@marbel 所建议的那样,fread 允许您在文本中传递 sed 调用.如:
Or as suggested by @marbel, fread allows you to pass the sed call inside the text. Such as:
fread("sed 's/\0//g' mycsv.csv")
这篇关于使用 fread 导入 csv 时出现“在字符串中嵌入 nul"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!