[R] sscanf equivalent

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Oct 7 19:39:46 CEST 2005


Why not use a text connection?

On Fri, 7 Oct 2005, Paul Roebuck wrote:

> 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 at 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
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list