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.
Value
check_ones()
: ReturnsNULL
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