| arg_length | R Documentation |
Checks whether an argument has a specified length.
arg_length(x, len = 1L, .arg = rlang::caller_arg(x), .msg = NULL, .call)
x |
the argument to be checked |
len |
|
.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. |
len can contain multiple allowed counts; an error will be thrown only if length(x) is not equal to any value of len.
Returns NULL invisibly if an error is not thrown.
length(), arg_non_null() to specifically test that an object's length is or is not 0.
obj <- 1:4
try(arg_length(obj, 1))
try(arg_length(obj, 4))
try(arg_length(obj, c(1, 4)))
# These test the same thing:
try(arg_length(obj, c(0:3)))
try(when_not_null(obj,
arg_length(1:3)))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.