I'm using Mac with RStudio 0.99.489 and R3.2.2. I have a csv file of 1GB, it's not exactly big but still takes around 5 min if I tried to import it with read.csv, and I have a lot files of this size so I tried fread()
. From reading the previous questions, I learned that this error might be because of missing values on date (a normal entries would be like '03May1995:15:31:50' for the date column, however, where the error occurs, it looks like '05May').
I tried sed 's/\\0//g' mycsv1.csv > mycsv2.csv
as mentioned in 'Embedded nul in string' error when importing csv with fread, but the same error message still pops up.
sed -i 's/\\0//g' /src/path/mycsv.csv
simply doesn't work for me, the terminal reports error for this command line (I'm not very familiar with those command lines, so I don't understand the logic behind those)
I tried
file <- "file.csv"
tt <- tempfile() # or tempfile(tmpdir="/dev/shm")
system(paste0("tr < ", file, " -d '\\000' >", tt))
fread(tt)
from 'Embedded nul in string' when importing large CSV (8 GB) with fread(), I guess it removed the entries where there is a missing value, because when I run fread(tt)
R says
Error in fread(tt) :
Expecting 5 cols, but line 5060627 contains text after processing all cols. It is very likely that this is due to one or more fields having embedded sep=',' and/or (unescaped) '\n' characters within unbalanced unescaped quotes.
After that, I tried iconv -f utf-16 -t utf-8 myfile1.csv > myfile2.csv
because it seems like this was caused by some problem with fread
can't comprehend utf-16, and there might be something wrong with this command line, but it simply gives me a spread sheet with random symbols.
And I saw this
vim filename.csv
:%s/CTRL+2//g
ESC #TO SWITCH FROM INSERT MODE
:wq # TO SAVE THE FILE
from Error with fread in R--embedded nul in string: '\0' but after I typed in vim filename.csv
, the terminal just read in the whole spreadsheet and I couldn't type in the 2nd command (:%s/CTRL+2//g
), again, I don't really understand those command lines, so maybe I need to make some adjustment to my situation.
Thanks for the help!