Test if a value is missing, empty, contains only NA or NULL values, or is a try-error.

invalid(x)

Arguments

x

value to be tested

Value

Logical value.

See also

Author

Gregory R. Warnes greg@warnes.net

Examples



invalid(NA)
#> [1] TRUE
invalid()
#> [1] TRUE
invalid(c(NA, NA, NULL, NA))
#> [1] TRUE

invalid(list(a = 1, b = NULL))
#> [1] FALSE

x <- try(log("A"))
#> Error in log("A") : non-numeric argument to mathematical function
invalid(x)
#> [1] TRUE

# example use in a function
myplot <- function(x, y) {
  if (invalid(y)) {
    y <- x
    x <- 1:length(y)
  }
  plot(x, y)
}
myplot(1:10)

myplot(1:10, NA)