Skip to content
Back to formatted view

Raw Message

Message-ID: <49AFF2C4.7080207@biostat.ku.dk>
Date: 2009-03-05T15:41:56Z
From: Peter Dalgaard
Subject: flow control
In-Reply-To: <77EB52C6DD32BA4D87471DCD70C8D700D22A1E@NA-PA-VBE03.na.tibco.com>

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