This function runs standard unit tests on numeric and integer parameters for functions.
Usage
dis_numeric(x, valid = NULL, null_valid = TRUE, na_valid = FALSE,
nan_valid = FALSE, infinite_valid = FALSE, integer = FALSE, scalar = TRUE,
param = NULL, call = NULL, fact_check = "global")Arguments
- x
Required object; a parameter argument to test.
- valid
Optional numeric scalar or vector; valid values for the parameter.
- null_valid
Required logical scalar; whether the parameter can be
NULL. IfFALSE, the function will throw an error ifxisNULL. Default isTRUE.- na_valid
Required logical scalar; whether the parameter can be
NA. IfFALSE, the function will throw an error ifxisNA. Default isFALSE.- nan_valid
Required logical scalar; whether the parameter can be
NaN. IfFALSE, the function will throw an error ifxisNaN. Default isFALSE.- infinite_valid
Required logical scalar; whether the parameter can be
Infor-Inf. IfFALSE, the function will throw an error ifxis infinite. Default isFALSE.- integer
Required logical scalar; whether the parameter must be an integer. If
TRUE, the function will throw an error ifxis not an integer. Default isFALSE.- scalar
Required logical scalar; whether the parameter must be a scalar. If
TRUE(default), the function will throw an error ifxis not a scalar.- param
Optional character scalar; the parameter name. If
NULL(default), the function will attempt to determine the parameter name from the calling environment. If nesting functions, it is recommended to provide the parameter name to ensure the correct parameter is referenced usingrlang::caller_arg().- call
Optional environment; the environment in which the function was called. If
NULL(default), the function will attempt to determine the calling environment. If nesting functions, it is recommended to provide the calling environment to ensure the correct environment is referenced usingrlang::caller_env().- fact_check
Required character scalar; whether to override fact checking environment setting. If
"global"(default),dis_characterwill follow the global setting. If"always",dis_characterwill ignore any global setting and will always checkx. This argument is primarily intended for Shiny developers who wish to usedisputeRin modules. See the vignette onvignette("developing", package = "disputeR")for details on how to use this function.
Value
This function will return either TRUE (if the input passes
all validation checks) or an error message. Note that, if the input is NULL,
NA, NaN, or infinite and the appropriate arguments are set
to TRUE, the detailed unit tests are skipped and the function will
return TRUE.
Details
See the vignette on vignette("developing", package = "disputeR")
for details about internal validation of arguments for this function.
Examples
# create example function that uses dis_numeric()
example <- function(x){
## check inputs with disputeR
dis_not_missing(.f = rlang::is_missing(x))
dis_numeric(x, null_valid = FALSE)
## square
out <- x^2
## return output
return(out)
}
# test example function
example(x = 2)
#> [1] 4