How could I import a file :
- starting with an undefined number of comment lines
- followed by a line with headers, some of them containing the comment character which is used to identify the comment lines above?
For example, with a file like this:
# comment 1
# ...
# comment X
c01,c#02,c03,c04
1,2,3,4
5,6,7,8
Then:
myDF = read.table(myfile, sep=',', header=T)
Error in read.table(myfile, sep = ",", header = T) : more columns than column names
The obvious problem is that # is used as comment character to announce comment lines, but also in the headers (which, admittedly, is bad practice, but I have no control on this).
The number of comment lines being unknown a priori, I can't even use the skip argument. Also, I don't know the column names (not even their number) before importing, so I'd really need to read them from the file.
Any solution beyond manually manipulating the file?
readLinesto import the whole thing as strings, then clean it up into a standard format. - Gregor Thomas