L: Assert a length

Description Usage Arguments Value See Also Examples

View source: R/coding.R

Description

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.

Usage

1
2
3
4
5
6
7
  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)

Arguments

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 storage.mode.

.msg

Error message passed to sprintf with the name of x and the value of wanted as the two additional arguments.

.domain

Passed to stop from the base package as argument ‘domain’.

Value

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.

See Also

base::stop

Other coding-functions: assert, case, check, collect, contains, flatten, listing, map_names, map_values, must, set, sql, unnest

Examples

1
2
3
4
5
6
(x <- L(letters, 26L))
stopifnot(identical(x, letters))
(x <- try(L(letters, 25L), silent = TRUE))
stopifnot(inherits(x, "try-error"))
(x <- LL(letters, LETTERS, .wanted = 26L))
stopifnot(x == c("letters", "LETTERS"))

pkgutils documentation built on May 2, 2019, 5:49 p.m.

Related to L in pkgutils...