Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Bill Dunlap
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Brahm, David
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Tony Plate
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Gabor Grothendieck
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Prof Brian Ripley
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Dominick Samperi
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

Re: [Rd] Strict seq: a recommendation

2006-08-23 Thread Thomas Lumley
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

[Rd] Strict seq: a recommendation

2006-08-23 Thread Dominick Samperi
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