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

Name of object defined in x. Not intended to be used directly.

Value

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

Note

Updated 2019-09-06.

Examples

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