| arg_logical | R Documentation |
Checks whether an argument is a logical vector (arg_logical()) or a logical scalar (arg_flag()), i.e., a single logical value. Logical values include TRUE and FALSE.
arg_logical(x, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_flag(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. |
NA values in arg_flag() will cause an error to be thrown.
Returns NULL invisibly if an error is not thrown.
is.logical(), rlang::is_bool()
obj <- TRUE
try(arg_flag(obj)) # No error
try(arg_logical(obj)) # No error
obj <- c(TRUE, FALSE)
try(arg_flag(obj)) # Error: must be a scalar
try(arg_logical(obj)) # No error
obj <- 1L
try(arg_flag(obj)) # Error must be logical
try(arg_logical(obj)) # Error must be logical
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.