[R] iteration introspection?
ggrothendieck at myway.com
Sat Aug 7 18:12:19 CEST 2004
<Ted.Harding <at> nessie.mcc.ac.uk> writes:
: On 06-Aug-04 Cere Davis wrote:
: > Hi everyone,
: > 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.
: > Does anyone know how I can learn what the value of my iterator
: > is within a loop?
: It's not clear from your description why you are thinking of
: using R for this.
: Normally, in the situation described in your first paragraph,
: I would run the file (in plain text format of course) through
I think the main potential benefit of using awk or other filter
to preprocess input is that it might be faster.
However, if that is not an issue the various string routines in R
such as substring, substr, paste, sub, gsub, regexp, nchar and
others are sufficiently powerful that these days I find that
I just do it all in R, not using awk or other external
filter at all. This has the advantage of keeping everything
in one language and making the code independent of external
programs which might vary by installation or OS.
More information about the R-help