Check if input is a character vector and meets specified criteria
Source:R/check_character.R
check-character.Rd
check_character()
and check_is_character()
functions verify
whether an input is a character vector and that it satisfies the specified
criteria check_character()
raises an error if the vector does not
meet the criteria, while check_is_character()
returns a logical value
indicating the result.
Value
check_character()
: Returns the original character vector or raises an error message if an error occurs or any of the conditions is not met.check_is_character()
: Logical value,TRUE
if the character vector meets the specified conditions, andFALSE
otherwise.
Examples
# Examples for check_character()
# ------------------------------
check_character("Hello")
#> [1] "Hello"
try(check_character("Hello", n = 10))
#> Error in check_character("Hello", n = 10) :
#> Expected 'char' to have exactly 10 characters but got 5 characters
check_character("Hello", n = 10, inequality = "<=")
#> [1] "Hello"
try(check_character(c("a", "b", "c")))
#> Error in check_character(c("a", "b", "c")) :
#> Expected 'char' to be a character vector of length 1 but got character with 3 elements
# Examples for check_is_character()
# ---------------------------------
check_is_character("Hello")
#> [1] TRUE
check_is_character("Hello", n = 10)
#> [1] FALSE
check_is_character("Hello", n = 10, inequality = "<=")
#> [1] TRUE
check_is_character(c("a", "b", "c"))
#> [1] FALSE