Re: [R] sscanf equivalent

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat 08 Oct 2005 - 03:39:46 EST

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

______________________________________________
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:46:20 2005

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