hadley / r-internals

Documentation for R's internal C API
346 stars 40 forks source link

Description of Rf_isNumeric doesn't match R-3.3.1 #5

Open BillDunlap opened 8 years ago

BillDunlap commented 8 years ago

https://github.com/hadley/r-internals/blob/master/vectors.md says Rboolean Rf_isNumber(SEXP); // INTSXP (but not factor), LGLSXP, REALSXP, CPLXSXP Rboolean Rf_isNumeric(SEXP); // INTSXP (but not factor), REALSXP, CPLXSXP but my experiments indicate the R-3.3.1's isNumeric returns TRUE for logical, integer, and real, but not complex or factor or other types and that isNumber returns TRUE for logical, integer, real, and complex, but not for factor or other types. I.e., both accept LGLSXP but only isNumber accepts CPLXSXP.

                      x isNumber isNumeric

Factor 1 FALSE FALSE Logical TRUE TRUE TRUE Integer 1 TRUE TRUE Real 1.1 TRUE TRUE Complex 1+1i TRUE FALSE List 2, 1 FALSE FALSE Character ABC FALSE FALSE Name Joe FALSE FALSE Expression expression({, }) FALSE FALSE Call Func(Arg) FALSE FALSE

hadley commented 8 years ago

Just double checked with the source and you are indeed correct. CPLSXPs are not numeric, but they are numbers. This is consistent with is.numeric() in R:

is.numeric(1 + 1i)
#> [1] FALSE