check_numeric_array()
and check_is_numeric_array()
functions
check whether the provided input is a numeric array or matrix. The
check_numeric_array()
function raises an error message if the input
is not a numeric array or matrix, while check_is_numeric_array()
returns TRUE
if the input is a valid numeric array or matrix and
FALSE
otherwise.
Value
check_numeric_array()
: Returns the original data entered if it is a valid numeric array or matrix. Raises an error message if the input is not a valid numeric array or matrix.check_is_numeric_array()
: Logical value,TRUE
if the input is a valid numeric array or matrix, andFALSE
otherwise.
Examples
# Examples for check_numeric_array()
# ----------------------------------
v <- c(1, 2, 3)
check_numeric_array(v)
#> [1] 1 2 3
v2 <- c("a", "b", "c")
try(check_numeric_array(v2))
#> Error in check_numeric_array(v2) :
#> Expected 'par_name' to be a numeric vector or matrix
A <- matrix(1:6, nrow = 2)
check_numeric_array(A)
#> [,1] [,2] [,3]
#> [1,] 1 3 5
#> [2,] 2 4 6
B <- matrix(c(TRUE, FALSE), nrow = 1)
try(check_numeric_array(B))
#> Error in check_numeric_array(B) :
#> Expected 'par_name' to be a numeric vector or matrix
C <- matrix(nrow = 0, ncol = 0)
try(check_numeric_array(C))
#> Error in check_numeric_array(C) :
#> Expected 'par_name' to be a numeric vector or matrix
# Examples for check_is_numeric_array()
# -------------------------------------
check_is_numeric_array(v)
#> [1] TRUE
check_is_numeric_array(v2)
#> [1] FALSE
check_is_numeric_array(A)
#> [1] TRUE
check_is_numeric_array(B)
#> [1] FALSE
check_is_numeric_array(C)
#> [1] FALSE