[R] FW: flow control

Peter Dalgaard P.Dalgaard at biostat.ku.dk
Thu Mar 5 16:41:56 CET 2009


William Dunlap wrote:
>    The help page for ?"for" says that:
> 
>    The index seq in a for loop is evaluated at the start of the loop;
> changing
>    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
> complicated
> 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.

Thank. We've put something more sensible into R-devel. Take a look at

http://svn.r-project.org/R/trunk/src/library/base/man/Control.Rd

-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907




More information about the R-help mailing list