[R] iteration introspection?
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Aug 6 20:11:58 CEST 2004
On Fri, 6 Aug 2004, Cere Davis wrote:
> I want to perform a regex substitution on line #1 in a file based on the
> contents of line #2. same is true for line 11 and line 12 etc...
> With the look at each line of a file rolling forward method it seems to
> me that I will not be able to use iterators like 'each' for this
> operation unless I am able to manipulate or even know of the position of
> the file pointer from within the iterator block but I don't know of a
> way to do this.
In R, we use connections to access files and the function seek() will tell
you where you are on the file and move you elsewhere, separately for read
and for write.
> Does anyone know how I can learn what the value of my iterator is within
> a loop?
The iterator is `i' in for(i in 1:n), so you can access it directly. I
suspect that was not the Q you wanted to ask.
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