Skip to contents

Does the input have dimensions?

Usage

hasDims(x, n = NULL)

hasRows(x, n = NULL)

hasCols(x, n = NULL)

Arguments

x

Object.

n

integer or NULL. Expected dimension number. For hasDims, integer(2) is required, corresponding to rows, columns. If NULL, only checks for non-zero dimensions.

Value

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

Note

Updated 2023-10-06.

See also

Examples

## TRUE ====
x <- datasets::mtcars
hasDims(x)
#> [1] TRUE
hasRows(x)
#> [1] TRUE
hasCols(x)
#> [1] TRUE

## Note that dims don't have to be non-zero, just not NULL.
hasDims(data.frame())
#> [1] TRUE

## Expected dimension number is supported.
x <- matrix(data = seq(from = 1L, to = 6L), nrow = 3L, ncol = 2L)
## For `hasDims`, `n` corresponds to rows, columns.
hasDims(x, n = c(3L, 2L))
#> [1] TRUE
hasRows(x, n = 3L)
#> [1] TRUE
hasCols(x, n = 2L)
#> [1] TRUE

## FALSE ====
x <- data.frame()
hasDims(list())
#> [1] FALSE
hasRows(x)
#> [1] FALSE
hasCols(x)
#> [1] FALSE