check_zeros()
and check_is_zeros()
check whether a matrix
contains only zero values. check_zeros()
raises an error if the
matrix contains non-zero values, while check_is_zeros()
returns
TRUE
if the matrix contains only zeros and FALSE
otherwise.
Value
check_zeros()
: ReturnsNULL
if the matrix contains only zeros, or raises an error if the matrix contains non-zero values.check_is_zeros()
: Logical value,TRUE
if the matrix contains only zeros,FALSE
otherwise.
Examples
# Examples for check_zeros()
# --------------------------
A <- matrix(0, nrow = 3, ncol = 3)
check_zeros(A)
#> [,1] [,2] [,3]
#> [1,] 0 0 0
#> [2,] 0 0 0
#> [3,] 0 0 0
B <- matrix(c(1, 0, 0, 0, 0, 0), nrow = 2, ncol = 3)
print(B)
#> [,1] [,2] [,3]
#> [1,] 1 0 0
#> [2,] 0 0 0
try(check_zeros(B))
#> Error in check_matrix_constant_with_k(mat = mat, k = 0, par_name = par_name) :
#> Expected 'mat' to be a zeros matrix
# Examples for check_is_zeros()
# -----------------------------
check_is_zeros(A)
#> [1] TRUE
check_is_zeros(B)
#> [1] FALSE