| L {pkgutils} | R Documentation |
Raise an error if one to several given R objects do not have the specified length. This is mainly used to easily generate meaningful error messages related to function arguments.
L(x, .wanted = 1L,
.msg = "need object '%s' of length %i",
.domain = NULL)
LL(..., .wanted = 1L,
.msg = "need object '%s' of length %i",
.domain = NULL)
x |
R object to test. |
... |
Any R objects to test. |
.wanted |
Integer scalar giving the desired length.
Note that this can not be a scalar with
‘double’ as |
.msg |
Error message passed to |
.domain |
Passed to |
If successful, L returns x, but an error
message is raised if length(x) is not identical to
wanted. LL yields the names of the
arguments contained in ..., returned invisibly,
if successful. Otherwise an error is raised.
base::stop
Other coding-functions: assert,
case, check, collect,
contains, flatten,
listing, map_names,
map_values, must,
set, sql,
unnest
(x <- L(letters, 26L))
## [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k" "l" "m" "n" "o" "p" "q"
## [18] "r" "s" "t" "u" "v" "w" "x" "y" "z"
stopifnot(identical(x, letters))
(x <- try(L(letters, 25L), silent = TRUE))
## [1] "Error : need object 'letters' of length 25\n"
## attr(,"class")
## [1] "try-error"
## attr(,"condition")
## <simpleError: need object 'letters' of length 25>
stopifnot(inherits(x, "try-error"))
(x <- LL(letters, LETTERS, .wanted = 26L))
## [1] "letters" "LETTERS"
stopifnot(x == c("letters", "LETTERS"))