Data.table: coalesce() can't handle NaN

Created on 26 Aug 2019  路  3Comments  路  Source: Rdatatable/data.table

Currently, NaN is treated as if a non-NA value but I expect it's the same as NA_real_, because is.na(NaN) returns TRUE.

library(data.table)
coalesce(NaN, 1)
#> [1] NaN
is.na(NaN)
#> [1] TRUE

Created on 2019-08-26 by the reprex package (v0.2.1)

dev

Most helpful comment

should be a matter of changing ISNA to ISNAN in https://github.com/Rdatatable/data.table/blob/d95910733167684b05ce253dcb4da801bde54f56/src/coalesce.c#L99-L118


the question is if we agree on such behaviour

All 3 comments

should be a matter of changing ISNA to ISNAN in https://github.com/Rdatatable/data.table/blob/d95910733167684b05ce253dcb4da801bde54f56/src/coalesce.c#L99-L118


the question is if we agree on such behaviour

I think that because is.na(NaN) default should be to consider it as NA. Both dplyr and hutils do so.

In the future, if requested, we could add an option, but I think we should do this for now.

(PS we're already doing this for complex input: coalesce(NaN + NaN*1i, 1 + 1i) -> 1+1i)

Was this page helpful?
0 / 5 - 0 ratings