Re: [Rd] bug in sum() on integer vector

From: John C Nash <>
Date: Wed, 14 Dec 2011 10:19:58 -0500

Following this thread, I wondered why nobody tried cumsum to see where the integer overflow occurs. On the shorter xx vector in the little script below I get a message:

Warning message:
Integer overflow in 'cumsum'; use 'cumsum(as.numeric(.))'

But sum() does not give such a warning, which I believe is the point of contention. Since cumsum() does manage to give such a warning, and show where the overflow occurs, should sum() not be able to do so? For the record, I don't class the non-zero answer as an error in itself. I regard the failure to warn as the issue.

For info, on my Ubnuntu Lucid 10.04 system that has 4 GB of RAM but no swap, the last line of the script to do the int64 sum chugs for about 2 minutes then gives "Killed" and returns to the terminal prompt. It also seems to render some other applications unstable (I had Thunderbird running to read R-devel, and this started to behave strangely after the crash, and I had to reboot.) I'm copying Romain as package maintainer, and I'll be happy to try to work off-list to figure out how to avoid the "Killed" result. (On a 16GB machine, I got the 0 answer.)


John Nash

Here's the system info and small script.

>> sessionInfo()
> R version 2.14.0 (2011-10-31)
> Platform: x86_64-pc-linux-gnu (64-bit)
> locale:
> [1] LC_CTYPE=en_US.utf8 LC_NUMERIC=C
> [3] LC_TIME=en_US.utf8 LC_COLLATE=en_US.utf8
> [5] LC_MONETARY=en_US.utf8 LC_MESSAGES=en_US.utf8
> attached base packages:
> [1] stats graphics grDevices utils datasets methods base
> other attached packages:
> [1] int64_1.1.2

## sumerr.R 20111214
x <- c(rep(1800000003L, 10000000), -rep(1200000002L, 15000000)) xx <- c(rep(1800000003L, 1000), -rep(1200000002L, 1500))



tmp<-readline("Now try the VERY SLOW int64") sum(as.int64(x)) mailing list Received on Wed 14 Dec 2011 - 15:22:23 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 14 Dec 2011 - 19:20:18 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive