Stavros Macrakis
2009-Jun-23 19:53 UTC
[Rd] Documentation/software inconsistency in `:` and seq
In 2.8.1/Windows: According to ? : Details: For numeric arguments 'from:to' is equivalent to 'seq(from, to)' ... Value: For numeric arguments, a numeric vector. This will be of type 'integer' if 'from' and 'to' are both integers and representable in the integer type, otherwise of type 'numeric'.... The first claim is inconsistent with the second; it appears that the first one is true and the second is false. Actual behavior: storage.mode(1:2.5) => integer storage.mode(`:`(from=1L,to=2.5)) => integer # just to be completely explicit But of course 2.5 is not an integer or equal to one. This is the same behavior as seq: storage.mode(seq(1,2.5)) => integer storage.mode(seq(from=1L,to=2.5)) => integer --------------------------------- On the other hand, according to ? seq Currently, the default method returns a result of type '"integer"' if 'from' is (numerically equal to an) integer This is not correct:> seq(1e16,1e16+10)[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[1] 0 0 2 4 4 4 6 8 8 8 10 # not enough precision to represent all the distinct integers, OK> storage.mode(seq(1e16,1e16+10))[1] "double" In this case, the ? : documentation is correct: This will be of type 'integer' if ... representable in the integer type, otherwise of type 'numeric'. [[alternative HTML version deleted]]
Martin Maechler
2009-Jun-24 09:28 UTC
[Rd] Documentation/software inconsistency in `:` and seq
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