Why is
isTRUE(NULL != 2)
[1] FALSE
And how would I receive TRUE?
In my real case I have variables and I want to process something, if the values differ. However, when one value is NULL I don't recognize them as different!
Why is
isTRUE(NULL != 2)
[1] FALSE
And how would I receive TRUE?
In my real case I have variables and I want to process something, if the values differ. However, when one value is NULL I don't recognize them as different!
As @Roland pointed out, we can't perform any logical operations directly on
NULL
object. To compare them we might need to perform an additional check ofis.null
and then perform the logical comparison.We can use
identical
instead to compare values which handles integers as well asNULL
.In order to answer the why part of your question:
Comparing
NULL
with other types will give youlogical(0)
(i.e., a logical vector of length zero). So,actually is
which is
FALSE
.In order to compare the values where you might have
NULL
values also, you could also do something like this (using short circuit logical operator):