[Rd] two minor bugs in rowsum()

William Dunlap wdunlap at tibco.com
Fri Mar 25 18:19:58 CET 2011


(a) In R 2.12.2 rowsum can overflow if given an integer input:
  > rowsum(c(2e9L, 2e9L), c("a", "a"))
          [,1]
  a -294967296
  > 2^32 + .Last.value
     [,1]
  a 4e+09
Should it be changed to coerce its x argument to numeric
(double precision) so it always returns a numeric output?

(b) When rowsum is given an x containing both NaN and NA it
appears to use the last of the NaN/NA entries to determine
if the output is NaN or NA while the `+` function uses the
first:
  > z <- cbind( c(NA,NA), c(NA,NaN), c(NaN,NA), c(NaN,NaN))
  > rowsum(z, c("a","a"))
    [,1] [,2] [,3] [,4]
  a   NA  NaN   NA  NaN
  > z[1,,drop=FALSE] + z[2,,drop=FALSE]
       [,1] [,2] [,3] [,4]
  [1,]   NA   NA  NaN  NaN

(The name rowsum is a metabug, since it may be confused
with the entirely different rowSums, but it has been around
for a long time.)

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 



More information about the R-devel mailing list