Skip to contents

Useful for quickly checking to see if we have dropped rows or columns containing all zeros.

Usage

hasNonzeroRowsAndCols(x)

Arguments

x

Object.

Value

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

Details

This is a common check when handling RNA-seq data prior to generating a heatmap or applying a log transformation, for example.

Note

Updated 2021-01-04.

Examples

## TRUE ====
x <- matrix(data = seq_len(4L), nrow = 2L)
print(x)
#>      [,1] [,2]
#> [1,]    1    3
#> [2,]    2    4
hasNonzeroRowsAndCols(x)
#> [1] TRUE

## FALSE ====
x <- matrix(data = rep(c(0L, 1L), times = 2L), nrow = 2L, byrow = FALSE)
print(x)
#>      [,1] [,2]
#> [1,]    0    0
#> [2,]    1    1
hasNonzeroRowsAndCols(x)
#> [1] FALSE

x <- matrix(data = rep(c(0L, 1L), times = 2L), nrow = 2L, byrow = TRUE)
print(x)
#>      [,1] [,2]
#> [1,]    0    1
#> [2,]    0    1
hasNonzeroRowsAndCols(x)
#> [1] FALSE