On Wed, 23 Aug 2006, Tony Plate wrote:
> The way I avoid this problem is to use seq(len=n) instead of 1:n.
> Of course, the syntax can get inconvenient for starting values other
> than 1 or 0, but I haven't found that to be much of a problem.
>
> Using the idiom 1:n in programming (as opposed to i
AM
To: r-devel@r-project.org
Subject: [Rd] Strict seq: a recommendation
In for loops of the form:
for(m in seq(beg,end))
...
when beg > end, the default behavior is
to decrement, and the action described
by ... is executed at least once.
On the other hand, if you view this
construction as a translation
The way I avoid this problem is to use seq(len=n) instead of 1:n.
Of course, the syntax can get inconvenient for starting values other
than 1 or 0, but I haven't found that to be much of a problem.
Using the idiom 1:n in programming (as opposed to interactive use)
results in errors commonly enou
This is a longstanding problem when programing with seq.
In the common case that one wants 1,...,n such that if n is zero
a zero length answer is wanted, one can write seq(length = n)
instead of 1:n. However, the general case is still a problem,
as you point out.
On 8/23/06, Dominick Samperi <[EM
On Wed, 23 Aug 2006, Thomas Lumley wrote:
> On Wed, 23 Aug 2006, Dominick Samperi wrote:
>
> > In for loops of the form:
> > for(m in seq(beg,end))
> > ...
> >
> > when beg > end, the default behavior is
> > to decrement, and the action described
> > by ... is executed at least once.
> >
> > On t
I should point out that this recommendation was not designed just
to accommodate C/C++, it was motivated by problems
with R code of the form:
for(m in seq(beg,end))
val <- x[m]
Take beg=1, end=0, for example. This results in
val <- x[0]
and R issues no error about the subscript being out
of bound
On Wed, 23 Aug 2006, Dominick Samperi wrote:
> In for loops of the form:
> for(m in seq(beg,end))
> ...
>
> when beg > end, the default behavior is
> to decrement, and the action described
> by ... is executed at least once.
>
> On the other hand, if you view this
> construction as a translation o
In for loops of the form:
for(m in seq(beg,end))
...
when beg > end, the default behavior is
to decrement, and the action described
by ... is executed at least once.
On the other hand, if you view this
construction as a translation of the C code:
for(m = beg; m < end; m++)
...
then the semantics