0

I have a large input file with data that looks like this:

345 33
671 34
304 35
266 36

Seems pretty standard. But I can't find any read.table parameters that even recognizes that there are two columns. The table that gets created is a column of seemingly random single-digit numbers, or an error saying that every line appears to contain embedded nulls. If I type lines <- "{data}", lines becomes

345\t33\n671\t34\n304\t35\n266\t36

But when I tell the table sep="\t" it doesn't help. I do have a header but I'm using skip=1 to make sure it's not causing issues. Is there a formatting trick I'm not aware of? I'm going to be dealing with files in this format regularly so I'd love a relatively low-effort solution.

Ethan D
  • 1
  • 1
  • Have you tried fread from data.table? – be_green Aug 22 '17 at 15:20
  • 1
    Could you provide a reproducible example? – Scarabee Aug 22 '17 at 15:25
  • Can you give the entire command line which uses `read.table` plz ? – Smich7 Aug 22 '17 at 15:26
  • `an error saying that every line appears to contain embedded nulls`: Have you tried `skipNul = TRUE`? – Scarabee Aug 22 '17 at 15:26
  • 1
    Update: fread did not work. Not sure how to give a reproducible example short of the lines output. Adding skipNul=T throws errors but works, and the resulting table seems accurate, so Scarabee has solved the problem. Thanks for your suggestions friends. The full read.table command is: test_report <- read.table("",skip=1,sep="\t",skipNul=T) – Ethan D Aug 22 '17 at 15:35
  • We really need more info to see what's going on. Please see https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for help. At the least, we need to know what your data looks like and what code you're running and in what order (for example, where is `lines<-""` being run, and why is the value of `lines` something else later?). – tkmckenzie Aug 22 '17 at 15:45
  • It's hard to know. Maybe there are particular lines causing trouble? If the file is as you show, with tabs and new lines, the default `read.table` works fine. Using the sample you share, `read.table(text = "345\t33\n671\t34\n304\t35\n266\t36")` works just fine. – Gregor Thomas Aug 22 '17 at 16:01

0 Answers0