Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

I was reading in a csv file.

Code is:

mydata = read.csv("mycsv.csv", header=True, sep=",", quote="\"") 

Get the following warning:

Warning message: In scan(file = file, what = what, sep = sep, quote = quote, dec = dec, : embedded nul(s) found in input

Now some cells in my CSV have missing values that are represented by "".

How do I write this code so that I do not get the above warning?

like image 395
user1172468 Avatar asked Apr 22 '14 02:04

user1172468


People also ask

What are embedded NULS in R?

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.

How do I read a csv file into R?

The CSV file to be read should be either present in the current working directory or the directory should be set accordingly using the setwd(…) command in R. The CSV file can also be read from a URL using read. csv() function.

Can Read table read CSV?

The read. table() method is used to read data from files. These can be . csv files or .


2 Answers

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") 
like image 78
nneonneo Avatar answered Oct 05 '22 11:10

nneonneo


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.

like image 22
Apex Chimps Avatar answered Oct 05 '22 13:10

Apex Chimps