[R] Fread: add one to skip string identifier
Jim Lemon
drjimlemon at gmail.com
Sun Jun 28 11:21:02 CEST 2015
Hi Trevor,
I couldn't work out how to do it with just fread, but perhaps this will help:
# create a test file
sink("test_fread.dat")
cat("This is the header of a file\n")
cat("that ends with the word *end*\n")
cat("Col1 Col2\n1 2\n3 4\n5 6\n")
sink()
# try to read it
test_con<-file("test_fread.dat","rt")
header_lines<-1
while(header_lines) {
nextline<-readLines(test_con,1)
header_lines<-length(grep("*end",nextline,fixed=TRUE))==0
}
fread_dat<-read.table(test_con,header=TRUE)
Jim
On Sat, Jun 27, 2015 at 2:16 AM, Trevor Davies <davies.trevor at gmail.com> wrote:
> I'm trying to read in a file using the function fread.
>
> The file that I'm trying to read in has about 100 lines of information I
> don't want prior to getting to my matrix of data that I do want. On the
> line prior to the data I want there is always a string identifier "*end*"
>
> The following fread call:
>
> impcoord <- fread('H:/SBE19plus_01907535_2015_06_17_0093.cnv',skip="*END*")
>
> almost gets me there but it starts reading AT *END* and I'd like to have it
> start the line after. I can't figure out how to make this work.
>
> I know I could have a two step function where I have a function scan the
> file to Identify the line that has *END* but I thought I could just do it
> with one fread() call.
>
> thanks for the help.
> Trevor
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list