| arg_no_NA | R Documentation |
Checks whether an argument does not contain any NA values (arg_no_NA()), contains only NA values (arg_all_NA()), or is a scalar NA (arg_is_NA()).
arg_no_NA(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_is_NA(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_all_NA(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)
x |
the argument to be checked |
.arg |
the name of the argument supplied to |
.msg |
an optional alternative message to display if an error is thrown instead of the default message. |
.call |
the execution environment of a currently running function, e.g. |
arg_no_NA() throws an error when anyNA(x) is 0. arg_all_NA() throws an error when all(is.na(x)) is not FALSE. arg_is_NA() throws an error when length(x) is not 1 or anyNA(x) is FALSE.
arg_no_NA() is useful for checking that a meaningful argument was supplied. arg_all_NA() and arg_is_NA() are primarily used for in arg_or() to denote that NA is an allowed argument.
Returns NULL invisibly if an error is not thrown.
arg_non_null(), arg_supplied(), anyNA()
f <- function(x) {
arg_no_NA(x) ## x must not be NA
}
try(f(1)) ## No error
try(f(NA)) ## Error: x is NA
try(f(c(1, NA, 3))) ## Error: x contains NA
f2 <- function(y) {
arg_all_NA(y) ## y must be NA
}
try(f2(NA)) ## No error
try(f2(c(NA, NA))) ## No error
try(f2(1)) ## Error: y is not NA
try(f2(c(1, NA, 3))) ## Error: y is not all NA
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.