sort of fread to read from a file at fixed positions?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

sort of fread to read from a file at fixed positions?

Gael de Lannoy
Hello everybody,

I need to read a file with a header (EDF files, recorded
electroencephalogram signals) that has fixed byte positions for each
field of its header.
These fields have no separator between them, for example:

<8 ascii name of the patient><10ascii start time of the recording><4
ascii ... > etc.

I read that perfectly in Octave by using fread, fseek and other
C-derived file access methods, but i dont see such a method being
avalaible in R? I read the scan help page but it doesn't seem to be able
to read x chars then from that position read another y chars then jump
at position 80 and read z chars etc.

Thanks in advance,

Gael de Lannoy.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Reply | Threaded
Open this post in threaded view
|

Re: sort of fread to read from a file at fixed positions?

Prof Brian Ripley
See ?read.fwf, and also the `R Data Import/Export Manual' that ships with
every copy of R.

Also, you can do in R in the way you describe for Octave with connections
and readChar (again, see the manual).


On Tue, 14 Mar 2006, Gael de Lannoy wrote:

> Hello everybody,
>
> I need to read a file with a header (EDF files, recorded
> electroencephalogram signals) that has fixed byte positions for each
> field of its header.
> These fields have no separator between them, for example:
>
> <8 ascii name of the patient><10ascii start time of the recording><4
> ascii ... > etc.
>
> I read that perfectly in Octave by using fread, fseek and other
> C-derived file access methods, but i dont see such a method being
> avalaible in R? I read the scan help page but it doesn't seem to be able
> to read x chars then from that position read another y chars then jump
> at position 80 and read z chars etc.
>
> Thanks in advance,
>
> Gael de Lannoy.
>
> ______________________________________________
> [hidden email] 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,                  [hidden email]
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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html