Validate whether a variable points to a certain exiting column in a table.
Source:R/validate.R
validateColumn.RdValidate whether a variable points to a certain exiting column in a table.
Usage
validateColumn(
column,
x,
type = c("character", "date", "logical", "numeric", "integer"),
validation = "error",
null = FALSE,
empty = TRUE,
nm = deparse1(substitute(column), backtick = TRUE),
call = parent.frame()
)Arguments
- column
Name of a column that you want to check that exist in
xtable.- x
Table to check if the column exist.
- type
Type of the column.
- validation
Whether to throw warning or error.
- null
Whether
NULLis accepted.- empty
Whether it can be empty.
- nm
Name to use in error messages. Defaults to the expression supplied to
column.- call
Passed to cli functions.
Examples
x <- dplyr::tibble(a = 1, b = "xxx")
validateColumn("a", x, validation = "warning")
#> [1] "a"
validateColumn("a", x, type = "character", validation = "warning")
#> Warning: ! a type must be a choice of: `character`; but it is numeric.
#> [1] "a"
validateColumn("a", x, type = "numeric", validation = "warning")
#> [1] "a"
validateColumn("not_existing", x, type = "numeric", validation = "warning")
#> Warning: ! not_existing column does not exist.
#> [1] "not_existing"