On Fri, 15 Jan 2021, Riccardo (Jack) Lucchetti wrote:
On Fri, 15 Jan 2021, Artur Bala wrote:
> Dear developers,
> I thought that the following "if" conditions are supposed to give the same
> results but they actually don't. And the 2nd "if" block ignores
"NA" values
Interesting.
The problem you report can be exemplified even more easily as
<hansl>
scalar z = NA
if z < 0
print "A"
else
print "B"
endif
</hansl>
Ouch! That's clearly wrong. I'm not sure how long it has been like
that, probably since the redefinition of NA in 2018.
IMO, an "if" expression involving NA should result in an error
unless it's an "equal to" or "not equal to" comparison, in which
case it should return 0 or 1, respectively, regardless of the term
to be compared, since NA is not equal to anything, even itself.
The ternary query operator is similar, except that it's sufficient
to return NA rather than flagging an error when the comparison is
indeterminate.
Following C-library rules one could say that comparisons of the sort
z < x, z > x, z <= x, z >= y should all give FALSE/0 rather than NA
if one or more of {z, x} are NA. I'm not sure if we want that.
Allin