-
Notifications
You must be signed in to change notification settings - Fork 1
/
character.R
31 lines (28 loc) · 990 Bytes
/
character.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#' Check Character
#'
#' Checks if x is a character vector with no attributes including names.
#'
#' @inheritParams params
#' @param coerce A flag indicating whether to coerce a factor to a character vector and drop attributes including names.
#'
#' @return An invisible copy of x (if it doesn't throw an error).
#' @seealso \code{\link{check_int}}
#' @export
#'
#' @examples
#' check_character("1", error = FALSE)
#' check_character(1:2, error = FALSE)
check_character <- function(x, coerce = FALSE,
x_name = substitute(x),
error = TRUE) {
lifecycle::deprecate_soft("0.5.1", "check_character()", "chk::chk_character()")
x_name <- chk_deparse(x_name)
check_flag_internal(coerce)
check_flag_internal(error)
if(coerce) {
if(is.factor(x)) x <- as.character(x)
if(is.character(x)) attributes(x) <- NULL
}
check_vector(x, values = c("", NA_character_), named = FALSE, x_name = x_name,
error = error)
}