[Rcpp-devel] inconsistent is_na() vs. is.na()
Dirk Eddelbuettel
edd at debian.org
Wed Oct 2 15:36:52 CEST 2013
On 2 October 2013 at 21:10, Thomas Tse wrote:
| For whatever reason R chose NaN to be a subset of NA_real_, so I think it's
| better for Rcpp (which aims to provide C++ functionality in R) to follow the
| convention of R ...
I would tend to agree. I just looked at your example on the train (but are
now at work).
We currently have 'stricter' is_na() / is_nan() at the C++ level which
'trigger' only on match. But as
|
| from the following tests in R we see that for most R function (especially those
| with na.rm argument), NaN and NA are actually treated in the same way:
|
| > x1 <- c(NaN, NA, 1.1, 2.2)
| > x2 <- c(NA, NA, 1.1, 2.2)
| > mean(x1)
| [1] NA
| > mean(x2)
| [1] NA
| > mean(x1, na.rm=TRUE)
| [1] 1.65
| > mean(x2, na.rm=TRUE)
| [1] 1.65
| > is.na(x1)
| [1] TRUE TRUE FALSE FALSE
| > is.na(x2)
| [1] TRUE TRUE FALSE FALSE
you show here, R's own is.na() is really an OR over either NA or NaN -- it
acts like it was
is.missing(x) { is.na(x) | is.nan(x) }
I think we should follow this.
| of coz, there're some subtle differences (priority) in doing calculations on
| them:
|
| > NaN + 1
| [1] NaN
| > NA + 1
| [1] NA
| > NA * Inf
| [1] NA
| > NaN * Inf
| [1] NaN
| > NaN * NA
| [1] NA
See ?NA, I believe this to be documented.
Dirk
| Thomas,
|
| On 2 October 2013 at 19:31, Thomas Tse wrote:
| | is_na() does not handles R's NaN correctly, for the below test.cpp:
| [...]
| | is it possible to apply this change in next release of Rcpp ?
|
| Certainly. Though Romain has a point:
|
| On 2 October 2013 at 13:36, Romain Francois wrote:
| | The question is that do we want to be consistent with R or do we want
| | something that makes sense.
| |
| | I believe that is_na should test if its argument is NA, and is_nan
| | should check if is NaN
|
| We have to make sure that we're doing is "consistent" for various definitions
| of consistent. IEEE754 only knows NaN and Inf; NA is an R extension.
|
| But from the top of my head I'd have to say I would want Rcpp to behave like
| R over behaving like C++. But I could be swayed. Other views?
|
| Dirk
|
| --
| Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
|
|
|
|
| ----------------------------------------------------------------------
| _______________________________________________
| Rcpp-devel mailing list
| Rcpp-devel at lists.r-forge.r-project.org
| https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list