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

You can try using the skipNul = TRUE option.

mydata = read.csv("mycsv.csv", quote = "\"", skipNul = TRUE)

From ?read.csv

Embedded nuls in the input stream will terminate the field currently being read, with a warning once per call to scan. Setting skipNul = TRUE causes them to be ignored.

It worked for me.


Might be a file that do not have CRLF, might only have LF. Try to check the HEX output of the file.

If so. Try running the file through awk:

awk '{printf "%s\r\n", $0}' file > new_log_file

Tags:

R