[Rd] Documentation/software inconsistency in `:` and seq
Martin Maechler
maechler at stat.math.ethz.ch
Wed Jun 24 11:28:06 CEST 2009
Hi Stavros,
>>>>> "SM" == Stavros Macrakis <macrakis at alum.mit.edu>
>>>>> on Tue, 23 Jun 2009 15:53:30 -0400 writes:
SM> In 2.8.1/Windows:
SM> According to ? :
SM> Details:
SM> For numeric arguments 'from:to' is equivalent to 'seq(from, to)' ...
that *is* definitely true as seq(from,to) leads to return(from:to)
SM> Value:
SM> For numeric arguments, a numeric vector. This will be of type
SM> 'integer' if 'from' and 'to' are both integers and representable
SM> in the integer type, otherwise of type 'numeric'....
SM> The first claim is inconsistent with the second; it appears that the first
SM> one is true and the second is false.
{1st, 2nd ... where do you start counting ?}
SM> Actual behavior:
SM> storage.mode(1:2.5) => integer
SM> storage.mode(`:`(from=1L,to=2.5)) => integer # just to be completely
SM> explicit
SM> But of course 2.5 is not an integer or equal to one.
Interestingly, because of an earlier posting on the topic,
two days ago (*), I have fixed the help page (and very slightly also
the code) of ":"
[for R-devel (to be 2.10.0 in October) only, because R 2.9.1
has already been in pre-release feature deep freeze ].
SM> This is the same behavior as seq:
SM> storage.mode(seq(1,2.5)) => integer
SM> storage.mode(seq(from=1L,to=2.5)) => integer
{of course, as I mentioned above}
SM> ---------------------------------
SM> On the other hand, according to ? seq
SM> Currently, the default method returns a result of type '"integer"'
SM> if 'from' is (numerically equal to an) integer
SM> This is not correct:
Yes, seq(from, to) {without further arguments} and "default"
'from', indeed returns from:to
and hence should probably either defer to the ":" help page
or copy-paste from it.
Martin Maechler, ETH Zurich
--------------------------------------------
(*)
------------------------------------------------------------------------
r48823 | maechler | 2009-06-22 17:57:05 +0200 (Mon, 22 Jun 2009)
Improve doc of ":" {and code very slightly, at the boundary of MAX_INT}
------------------------------------------------------------------------
>> seq(1e16,1e16+10)
SM> [1] 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16 1e+16
>> seq(1e16,1e16+10)-1e16
SM> [1] 0 0 2 4 4 4 6 8 8 8 10 # not enough precision to represent
SM> all the distinct integers, OK
>> storage.mode(seq(1e16,1e16+10))
SM> [1] "double"
SM> In this case, the ? : documentation is correct:
SM> This will be of type 'integer' if ... representable in the integer
SM> type, otherwise of type 'numeric'.
SM> [[alternative HTML version deleted]]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{I'm amazed that you still did not find out how to avoid the
above, e.g., by following the posting guide ...}
SM> ______________________________________________
SM> R-devel at r-project.org mailing list
SM> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list