Get "Embedded Nul(S) Found in Input" When Reading a CSV Using Read.Csv()

Get embedded nul(s) found in input when reading a csv using read.csv()

Your CSV might be encoded in UTF-16. This isn't uncommon when working with some Windows-based tools.

You can try loading a UTF-16 CSV like this:

read.csv("mycsv.csv", ..., fileEncoding="UTF-16LE")

Read.csv() throws error

read.csv doesn't read XLS(X) files, only CSV files. Try opening your Excel file in Excel, exporting it to CSV and reissuing your read.csv command (depending on your system language, you might want to use read.csv2 instead).

Issues importing a csv in R

I finally found the solution!
I was going nuts; even my instructor didn't know how to fix it!

This statement works:

o<-read.csv("C:/Users/Admin/Desktop/-=Data Science=-/11-27-2018/Occ.txt", header=T, sep="\t", fileEncoding="UTF-16LE")

Like I said in my original question: I tried using fileEncoding="UTF-16LE" and it didn't help. After asking the question, I tried using sep="\t", and it didn't help. But using both of them did the trick!

Embedded nul in string' error when importing csv with fread

We can remove the null terminators on the command line using something like:

sed 's/\\0//g' mycsv.csv > mycsv.csv

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")


Related Topics



Leave a reply



Submit