readr: the read_delim function throws error "embedded nul in string: '\0'"

3.3k views Asked by At

I am using the readr library and read_delim function in R. I have a big file it has null spaces, so I run the function like this:

read_delim(paste0(dir,name,".txt"),delim="\t",
col_types=paste0(c(rep("c",17),rep("_",10),rep("c",2),rep("_",2),rep("c",1),rep("_",28),rep("c",1),rep("c",3),rep("c",12),rep("_",3),rep("c",1),rep("_",4),rep("c",21)),collapse=""),escape_backslash=T,na="NA",quote="'\"",n_max=6,progress=interactive())

This code throws the following error:

Error in read_tokens(ds, tokenizer, col_types, col_names, n_max = n_max, : embedded nul in string: '\0'

I tried to change "quote" parameter for quote="":

read_delim(paste0(dir,name,".txt"),delim="\t",
col_types=paste0(c(rep("c",17),rep("_",10),rep("c",2),rep("_",2),rep("c",1),rep("_",28),rep("c",1),rep("c",3),rep("c",12),rep("_",3),rep("c",1),rep("_",4),rep("c",21)),collapse=""),escape_backslash=T,na="NA",quote="",n_max=6,progress=interactive())

This function reads my file but the columns mismatched outputting incorrectly.

How can I correct this error?

0

There are 0 answers