title: How to skip extra lines before the header of a tab delimited delimited file in R
body: <p>The software I am using produces log files with a variable number of lines of summary information followed by lots of tab delimited data. I am trying to write a function that will read the data from these log files into a data frame ignoring the summary information. The summary information never contains a tab, so the following function works:</p>
  
  <pre><code>read.parameters &lt;- function(file.name, ...){
    lines &lt;- scan(file.name, what="character", sep="\n")
    first.line &lt;- min(grep("\\t", lines))
    return(read.delim(file.name, skip=first.line-1, ...))
  }
  </code></pre>
  
  <p>However, these logfiles are quite big, and so reading the file twice is very slow. Surely there is a better way?</p>
  
  <p><b>Edited to add:</b></p>
  
  <p>Marek suggested using a <code>textConnection</code> object. The way he suggested in the answer fails on a big file, but the following works:</p>
  
  <pre><code>read.parameters &lt;- function(file.name, ...){
    conn = file(file.name, "r")
    on.exit(close(conn))
    repeat{
      line = readLines(conn, 1)
      if (length(grep("\\t", line))) {
        pushBack(line, conn)
        break}}
    df &lt;- read.delim(conn, ...)
    return(df)}
  </code></pre>
  
  <p><b>Edited again:</b> Thanks Marek for further improvement to the above function.</p>