How to skip extra lines before the header of a tab delimited delimited file in R

Posted by Michael Dunn on Stack Overflow See other posts from Stack Overflow or by Michael Dunn
Published on 2010-06-16T12:13:40Z Indexed on 2010/06/16 12:32 UTC
Read the original article Hit count: 258

Filed under:
|
|

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:

read.parameters <- function(file.name, ...){
  lines <- scan("tmp.log", what="character", sep="\n")
  first.line <- min(grep("\\t", lines))
  return(read.delim(file.name, skip=first.line-1, ...))
}

However, these logfiles are quite big, and so reading the file twice is very slow. Surely there is a better way?

© Stack Overflow or respective owner

Related posts about r

    Related posts about csv