[Rd] Re: [R] Is k equivalent to k:k ?

Duncan Murdoch murdoch at stats.uwo.ca
Fri Dec 10 14:38:34 CET 2004


On Fri, 10 Dec 2004 09:32:14 +0100, Martin Maechler
<maechler at stat.math.ethz.ch> wrote :

>    RichOK> If you want to pass seq(length=n) to a .C or
>    RichOK> .Fortran call, it's not helpful that you can't tell
>    RichOK> what the type is until you know n!  It would be nice
>    RichOK> if seq(length=n) always returned the same type.  I
>    RichOK> use seq(length=n) often instead of 1:n because I'd
>    RichOK> like my code to work when n == 0; it would make life
>    RichOK> simpler if seq(length=n) and 1:n were the same type.
>
>now if that really makes your *life* simpler, what does that
>tell us about your life  ;-) :-)
>
>But yes, you are right.  All should return integer I think.

Yes, it should be consistent, and integer makes sense here.

However, as a matter of defensive programming, one should almost
always explicitly set the type (using  as.integer for example) in a .C
or .Fortran call:  those languages care quite a bit about the storage
mode, and give bizarre and hard to debug errors when it is wrong.   If
you did this, you wouldn't care that seq(length=n) returns mode
double.

It might waste a few cpu cycles, but programmer debugging cycles are
much more expensive.  

Duncan Murdoch



More information about the R-devel mailing list