2

Possible Duplicate:
cannt read file with “#” and space using read.table or read.csv in R

I have the problem with R that when I'm reading in (using read.table function) delimited files (e.g. tab-delimited text files) with R, the rows containing # or ' characters are silently dropped. how the file should be read in so that the rows containing these characters aren't dropped?

SRhm
  • 459
  • 1
  • 5
  • 11
Leo.peis
  • 13,673
  • 6
  • 22
  • 20

1 Answers1

6

The default comment.char is the # character. You can change this using the comment.char argument, i.e.

read.table(file, comment.char="@")
read.table(file, comment.char="##")
csgillespie
  • 59,189
  • 14
  • 150
  • 185
  • The problem is that I would need to ignore both # and ' at the same time. – Leo.peis Nov 06 '12 at 13:10
  • 2
    You can feed `comment.char` a vector: `comment.char=c("#", "'")` – Drew Steen Nov 06 '12 at 13:16
  • as I said above, you probably need to use `quote=""` to get `read.table` to ignore single quotes (') – Ben Bolker Nov 06 '12 at 14:30
  • 1
    @DrewSteen Actually Drew, putting an array results in an invalid comment.char argument error. This feature would be beneficial. I have the problem of a flat file which is 90% space-separated numeric, with a few comments scattered here and there. The comments aren't preceeded with something standard such as # or %, it is surprisingly difficult to handle. I wish I could put an array into this containing every letter of the alphabet, but it doesn't work. I cant believe this F**kwits that provide data that don't consider the people that have to analyse it.... – Nicholas Hamilton Feb 05 '13 at 04:59