Does the input have row names?

hasRownames(x, .xname = getNameInParent(x))

Arguments

x

Object.

.xname

Not intended to be used directly.

Value

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

data.frame

Standard data.frame class objects cannot have NULL row names defined. Here we are checking to see if a data.frame has soft NULL row names, meaning that they return as a sequence that is identical to the number of rows.

Examples

## TRUE ==== x <- data.frame( "sample1" = c(1L, 2L), "sample2" = c(3L, 4L), row.names = c("gene1", "gene2") ) print(x)
#> sample1 sample2 #> gene1 1 3 #> gene2 2 4
hasRownames(x)
#> [1] TRUE
## FALSE ==== x <- data.frame(a = seq_len(2L)) print(x)
#> a #> 1 1 #> 2 2
# Standard data frame doesn't allow NULL row names. rownames(x)
#> [1] "1" "2"
hasRownames(x)
#> [1] FALSE #> Cause of failure: #> x has sequence row names (soft NULL).
x <- S4Vectors::DataFrame(a = seq_len(2L)) print(x)
#> DataFrame with 2 rows and 1 column #> a #> <integer> #> 1 1 #> 2 2
# S4 data frame does allow NULL row names. rownames(x)
#> NULL
hasRownames(x)
#> [1] FALSE #> Cause of failure: #> x has NULL row names.