0

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?

armatita
  • 12,825
  • 8
  • 48
  • 49
narteaga
  • 147
  • 2
  • 12
  • You don't need to inform `col_types` because they will be imputed from the first 30 rows on the input file. It's hard to know if this is the problem without a reproducible example, but try the same code without `col_types`. I think this should solve your problem. – rafa.pereira Sep 28 '15 at 14:55
  • Shouldn't make a difference, but `read_tsv` is appropriate for tab delimited files. – Gregor Thomas Jun 01 '16 at 17:11

0 Answers0