title: Import data into R with an unknown number of columns?
body: <p>I'm trying to read a text file with different row lengths:</p>
  
  <pre><code>1
  1   2
  1   2   3
  1   2   3   4
  1   2   3   4   5
  1   2   3   4   5   6
  1   2   3   4   5   6   7
  1   2   3   4   5   6   7   8
  </code></pre>
  
  <p>To overcome this problem, I'm using the argument fill=TRUE in read.table, so:</p>
  
  <pre><code>data&lt;-read.table("test",sep="\t",fill=TRUE)
  </code></pre>
  
  <p>Unfortunately, to assess the maximum row length, read.table reads only the first 5 lines of the file, and generates an object looking like this:</p>
  
  <pre><code>data
     V1 V2 V3 V4 V5
  1   1 NA NA NA NA
  2   1  2 NA NA NA
  3   1  2  3 NA NA
  4   1  2  3  4 NA
  5   1  2  3  4  5
  6   1  2  3  4  5
  7   6 NA NA NA NA
  8   1  2  3  4  5
  9   6  7 NA NA NA
  10  1  2  3  4  5
  11  6  7  8 NA NA
  </code></pre>
  
  <p>Is there a way to force read.table to scroll over the whole file to assess the maximum row length?
  I know a possible solution would be to provide the column number, like:</p>
  
  <pre><code>data&lt;-read.table("test",sep="\t",fill=TRUE,col.names=c(1:8))
  </code></pre>
  
  <p>But since I have a lot of files, I wanted to assess this automatically within R. Any suggestion? :-)</p>
  
  <hr>
  
  <p>EDIT: the original file doesn't contain progressive numbers, so this is not a solution:</p>
  
  <pre><code>data1&lt;-read.table("test",sep="\t",fill=TRUE)
  data2&lt;-read.table("test",sep="\t",fill=TRUE,col.names=c(1:max(data1))
  </code></pre>