[R] FW: flow control

William Dunlap wdunlap at tibco.com
Wed Mar 4 22:41:39 CET 2009

   The help page for ?"for" says that:

   The index seq in a for loop is evaluated at the start of the loop;
   it subsequently does not affect the loop. The variable var has the
same type
   as seq, and is read-only: assigning to it does not alter seq.

The help file is not right when seq is a list() or other recursive
type.  In that case var has the type of seq[[i]] where i is the current
iteration count.  (I think this is true in general, since [ and [[ act
the same for nonrecursive types when the indices are such that a scalar
would be returned.  However that explanation is unnecessarily
in the nonrecursive case.)

Also, the variable var is not really read-only.  You can alter it but
it gets reset to the next value in seq at the start of each iteration.
You cannot affect the meaning of 'next' to force it to, e.g, omit or
repeat iterations.

Bill Dunlap
TIBCO Software Inc - Spotfire Division
wdunlap tibco.com 

More information about the R-help mailing list