Skip to content

matrix() can't handle NaN (PR#193)

2 messages · Ben Bolker, Bill Simpson

#
On Tue, 11 May 1999, Bill Simpson wrote:
[examples with read.table(...,na.strings="NaN") snipped]
I'm going to defer this to people who know more than I about 
consistency and the differences between NA and NaN.  I will note that
the help for is.na() says:

The generic function `is.na' returns a logical vector of the same ``form''
as its argument `x', containing `TRUE' for those elements marked `NA' or
`NaN' (!) and `FALSE' otherwise.

  The (!) suggests that whoever wrote the help file recognized some 
subtlety here ... [similarly, is.finite() recognizes NA as a non-finite 
number]

  This seems to fall in the general category of "how do we help people 
avoid 'gotchas' in R that, while logical, are not necessarily what they 
expect?  Can we do this without blurring logical distinctions that are 
interesting/important/significant to more knowledgeable users?"

  One *could* extend the default na.strings in read.table to 
c("NA","NaN"), which would take care of the immediate problem but might 
further blur the subtle distinction between NA and NaN.  I don't know 
how/whether one would want to extend read.table() to deal with Inf/-Inf 
in data files ... (I think not).

  Ben
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
#
On Tue, 11 May 1999, Ben Bolker wrote:
My attitude is that if NaN is a recognized "number" by the numerical
analysts (the guys who write the floating point standards), why not treat
it as such throughout R? But maybe this opens a can of worms.

In my example, I was expecting to have the z matrix for an image plot with
NaNs in it. Then I was going to convert them either to zeros or NAs prior
to making the plot.

I would put the onus on the user to deal with the NaNs prior to
passing the data onto some other function. I would not favour some
automatic conversion of NaN into NA.

Bill

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._