isTRUE {base} | R Documentation |
isTRUE(x) is the same as { is.logical(x) && length(x) == 1 && !is.na(x) && x };
isFALSE() is defined analogously. Consequently, if(isTRUE(cond)) may be preferable to if(cond) because
of NAs.
In earlier R versions, isTRUE <- function(x) identical(x, TRUE), had the drawback to be false e.g.,
for x <- c(val = TRUE).
isTRUE(x);
# TRUE
isTRUE(TRUE);
# FALSE
isTRUE("TRUE");
# FALSE
isTRUE(FALSE);
# FALSE
isTRUE([TRUE TRUE]);