Skip to contents

Check whether an object is a single missing value (NA).

Usage

isNA(x)

Arguments

x

an object to be tested.

Value

logical scalar. Returns TRUE if x is a single missing value (NA), and FALSE otherwise.

Details

This is a strict helper that returns TRUE only if x is an atomic vector of length one and equal to NA. In contrast to is.na(), which is vectorized, isNA is intended for scalar checks, e.g. in conditional statements.

This function differs from is.na() in that it:

  • Only returns TRUE for length-one inputs

  • Returns a single logical value (not vectorized)

  • Works consistently across all NA types

See also

Other vector.na: coalesceX(), locf(), naIf(), naReplace()

Examples

isNA(NA)             # TRUE
#> [1] TRUE
isNA(NA_real_)       # TRUE
#> [1] TRUE
isNA(NA_integer_)    # TRUE
#> [1] TRUE

isNA(c(NA, NA))      # FALSE (length > 1)
#> [1] FALSE
isNA(NULL)           # FALSE
#> [1] FALSE
isNA(1)              # FALSE
#> [1] FALSE
isNA(c(1, NA))       # FALSE
#> [1] FALSE