HenrikBengtsson / matrixStats

R package: Methods that Apply to Rows and Columns of Matrices (and to Vectors)
https://cran.r-project.org/package=matrixStats
203 stars 33 forks source link

sum2(x, mode = "coerce"): when mode(x) is integer, return double if integer is not enough #128

Open HenrikBengtsson opened 6 years ago

HenrikBengtsson commented 6 years ago

Background

In R-devel svn rev >= 74208 (2018-02-11), y <- base::sum(x) will now return mode(y) = "numeric" in case y > 2^31-1. See also the R-devel thread 'sum() returns NA on a long logical vector when nb of TRUE values exceeds 2^31' started on 2017-06-02 for the reasons behind this.

Suggestion

Add option for sum2() to emulate this new behavior. This could be done as:

y <- matrixStats::sum2(x, mode = "sufficient")

or mode = "coerce", mode = "agile", or similar. An alternative could be to introduce a new argument onOverflow = "numeric".

What the default behavior should be can be discussed later; I don't think it affects the decision to implement this feature or not.