Check valid numeric vector
check_valid_numeric.RdCheck if arg is a numeric vector with no missing values (NA or NaN) and length greater than zero.
Arguments
- arg
(object)
The argument to check.- signal
(string:
c("error", "warning", "message"))
Must be one of"error","warning", or"message"."error"(default) callsbase::stop()to signal an error message."warning"callsbase::warning()to signal a warning message."message"callsbase::message()to signal a message.- msg
(string or
NULL:NULL)
A string that replaces the default message. Set asNULLto use the default message.- call.
(Scalar logical:
c(FALSE, TRUE))
Passed tostop()orwarning(). The defaultmsgincludes it's own formatted call, hencecall.should beFALSE(default). If you insert your ownmsg, then you may wantcall. = TRUE.
Details
This is a shortcut for the chain check_numeric() and check_valid().
Infinite values are allowed.
Use check_real() to also require finite values.
See also
Other check_type:
check_atomic(),
check_character(),
check_data_frame(),
check_data_frame_or_matrix(),
check_date(),
check_date_or_datetime(),
check_datetime(),
check_double(),
check_factor(),
check_flag(),
check_formula(),
check_function(),
check_function_or_numeric(),
check_inherits(),
check_integer(),
check_list(),
check_logical(),
check_matrix(),
check_named(),
check_nonempty_string(),
check_nonmissing(),
check_numeric(),
check_numeric_or_logical(),
check_probability(),
check_real(),
check_scalar_character(),
check_scalar_date(),
check_scalar_datetime(),
check_scalar_double(),
check_scalar_factor(),
check_scalar_integer(),
check_scalar_logical(),
check_scalar_numeric(),
check_scalar_probability(),
check_scalar_whole_number(),
check_scalar_whole_numeric(),
check_string(),
check_table(),
check_valid(),
check_whole_number(),
check_whole_numeric()
Examples
#----------------------------------------------------------------------------
# check_valid_numeric() examples
#----------------------------------------------------------------------------
library(bkcheck)
f <- function(x) {
x |>
check_valid_numeric()
}
integer <- 1:4
numeric <- c(1, 1.5)
character <- letters[1:4]
f(integer)
f(numeric)
f(c(1, Inf))
try(f(character))
#> Error : Argument `x` must be a non-missing numeric vector with length greater
#> than zero.
#>
#> class(x) = 'character'
#> length(x) = 4
#>
#> Call: f(x = character)
try(f(numeric(0)))
#> Error : Argument `x` must be a non-missing numeric vector with length greater
#> than zero.
#>
#> class(x) = 'numeric'
#> length(x) = 0
#>
#> Call: f(x = numeric(0))
try(f(c(1, NA)))
#> Error : Argument `x` must be a non-missing numeric vector with length greater
#> than zero.
#>
#> Missing at: 2
#> class(x) = 'numeric'
#> length(x) = 2
#>
#> Call: f(x = c(1, NA))