[R] sscanf equivalent

From: Paul Roebuck <roebuck_at_wotan.mdacc.tmc.edu>
Date: Sat 08 Oct 2005 - 03:22:49 EST


I have a data file from which I need to read portions of data but data location/quantity can change from file to file. I wrote some code and have a working solution but it seems wasteful to have to do it this way. Here's the contrived incomplete code.

    datalines <- readLines(datafile.pathname)
# marker will appear on line preceding and following
# actual data

    offset.data <- grep("marker", datalines)     datalines <- NULL

# grab first column of each assoc dataline
    data <- scan(datafile.pathname,

                 what = numeric(0),
                 skip = offset.data[1],
                 nlines = offset.data[2]-offset.data[1]-1,
                 flush = TRUE,
                 multi.line = FALSE,
                 quiet = TRUE)

# output is vector of values

Originally wrote code to parse data from 'datalines' using sub and strsplit methods but it was woefully slower and more complex than using scan method. What is desired is a means of invoking method like scan but with existing data instead of filename.



SIGSIG -- signature too long (core dumped)

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Oct 08 03:28:39 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:39 EST