| arg_between | R Documentation |
Checks whether values are within a range (arg_between()), greater than some value (arg_gt()), greater than or equal to some value (arg_gte()), less than some value (arg_lt()), or less than or equal to some value (arg_lte()).
arg_between(
x,
range = c(0, 1),
inclusive = TRUE,
.arg = rlang::caller_arg(x),
.msg = NULL,
.call
)
arg_gt(x, bound = 0, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_gte(x, bound = 0, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_lt(x, bound = 0, .arg = rlang::caller_arg(x), .msg = NULL, .call)
arg_lte(x, bound = 0, .arg = rlang::caller_arg(x), .msg = NULL, .call)
x |
the argument to be checked |
range |
a vector of two values identifying the required range. |
inclusive |
a logical vector identifying whether the range boundaries are inclusive or not. If only one value is supplied, it is applied to both range boundaries. Default is |
.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. |
bound |
the bound to check against. Default is 0. |
x is not checked for type, as it is possible for values other than numeric values to be passed and compared; however, an error will be thrown if typeof(x) is not equal to typeof(range) or typeof(bound). NA values of x will be removed. The arguments to range, inclusive, and bound are checked for appropriateness.
Returns NULL invisibly if an error is not thrown.
z <- 2
try(arg_between(z, c(1, 3))) # No error
try(arg_between(z, c(1, 2))) # No error
try(arg_between(z, c(1, 2),
inclusive = FALSE)) # Error
try(arg_between(z, c(1, 2),
inclusive = c(TRUE, FALSE))) # Error
try(arg_gt(z, 0)) # No error
try(arg_gt(z, 2)) # Error
try(arg_gte(z, 2)) # No error
try(arg_lt(z, 0)) # Error
try(arg_lt(z, 2)) # Error
try(arg_lte(z, 2)) # No error
try(arg_lte(z, "3")) # Error: wrong type
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.