Check arguments, and generate readable error messages.
Install erify from CRAN:
install.packages("erify")Or install the development version from Github:
# install devtools if not
# install.packages("devtools")
devtools::install_github("flujoo/erify")Load erify:
library(erify)Check if the following argument is valid:
arg <- "I'm invalid."For example, check if it has valid type:
check_type(arg, "integer")
#> Error: `arg` must have type integer.
#>
#> ✖ `arg` has type character.Check if it has valid length:
check_length(arg, 1)Or check if it is a positive integer:
check_n(arg)
#> Error: `arg` must be a single positive integer.
#>
#> ✖ `arg` has type character.See vignette("erify", package = "erify") for a gentle introduction to
erify.