Skip to contents

check_ones() and check_is_ones() check whether a matrix contains only one values. check_ones() raises an error if the matrix contains non-one values, while check_is_ones() returns TRUE if the matrix contains only ones and FALSE otherwise.

Usage

check_ones(mat, par_name = "mat")

check_is_ones(mat)

Arguments

mat

The matrix to check.

par_name

A name for the parameter mat to display in error messages.

Value

  • check_ones(): Returns NULL if the matrix contains only ones, or raises an error if the matrix contains non-one values.

  • check_is_ones(): Logical value, TRUE if the matrix contains only ones, FALSE otherwise.

Examples

# Examples for check_ones()
# -------------------------
A <- matrix(1, nrow = 3, ncol = 3)
check_ones(A)
#>      [,1] [,2] [,3]
#> [1,]    1    1    1
#> [2,]    1    1    1
#> [3,]    1    1    1

B <- matrix(c(1, 1, 0, 1, 1, 1), nrow = 2, ncol = 3)
print(B)
#>      [,1] [,2] [,3]
#> [1,]    1    0    1
#> [2,]    1    1    1
try(check_ones(B))
#> Error in check_matrix_constant_with_k(mat = mat, k = 1, par_name = par_name) : 
#>   Expected 'mat' to be a ones matrix

# Examples for check_is_ones()
# ----------------------------
check_is_ones(A)
#> [1] TRUE
check_is_ones(B)
#> [1] FALSE