Skip to contents

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

Usage

hasLength(x, n = NULL)

Arguments

x

Object.

n

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

Value

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

Note

Updated 2023-09-29.

Examples

## TRUE ====
hasLength(1L)
#> [1] TRUE
hasLength(FALSE)
#> [1] TRUE
hasLength(datasets::mtcars)
#> [1] TRUE
hasLength("")
#> [1] TRUE

## FALSE ====
hasLength(NULL)
#> [1] FALSE
hasLength(character())
#> [1] FALSE
hasLength(data.frame())
#> [1] FALSE