Fast validation of numeric values with basic range checking.
Simplified utility function for common validation needs.
Usage
check_numeric_value(value, name, min_val = -Inf, max_val = Inf)
Arguments
- value
Value to validate
- name
Parameter name for error messages
- min_val
Minimum allowed value (default -Inf)
- max_val
Maximum allowed value (default Inf)
Value
The original value (numeric, same length as input),
returned unchanged when all checks pass. Throws an error if value
is NULL, non-numeric, contains non-finite elements (NA,
NaN, Inf), or falls outside [min_val, max_val].
Details
Performs essential validations:
Examples
check_numeric_value(5, "weight")
#> [1] 5
try(check_numeric_value(-1, "weight", min_val = 0))
#> Error : weight: 1 value(s) below minimum 0.000 (smallest: -1.000)
try(check_numeric_value(NA, "weight"))
#> Error : weight must be numeric