Does the input have a non-zero or defined length?

hasLength(x, n = NULL, .xname = getNameInParent(x))

Arguments

x

Object.

n

NULL or integer. If NULL (default), the function will check to see if the input length is non-zero.

.xname

Not intended to be used directly.

Value

TRUE on success; FALSE on failure, with cause attribute set.

Examples

## TRUE ==== hasLength(1L)
#> [1] TRUE
hasLength(FALSE)
#> [1] TRUE
hasLength(datasets::mtcars)
#> [1] TRUE
hasLength("")
#> [1] TRUE
## FALSE ==== hasLength(NULL)
#> [1] FALSE #> Cause of failure: #> NULL has length 0.
hasLength(character())
#> [1] FALSE #> Cause of failure: #> character() has length 0.
hasLength(data.frame())
#> [1] FALSE #> Cause of failure: #> data.frame() has length 0.