Asserts that a data frame contains the specified columns.
Usage
assert_cols(
data,
cols = NULL,
strict = FALSE,
obj_name = checkmate::vname(data)
)
See also
Other data frame / tibble functions:
is_equal_df()
,
reduce_df_list()
Examples
pal::assert_cols(data = mtcars,
cols = c("mpg", "disp"))
try(
pal::assert_cols(data = mtcars,
cols = c("mpg", "display"))
)
#> Error in pal::assert_cols(data = mtcars, cols = c("mpg", "display")) :
#> Assertion on 'mtcars' failed: Column names must include the elements {'mpg','display'}, but is missing elements {'display'}.
try(
pal::assert_cols(data = mtcars,
cols = c("mpg", "disp"),
strict = TRUE)
)
#> Error in pal::assert_cols(data = mtcars, cols = c("mpg", "disp"), strict = TRUE) :
#> Assertion on 'mtcars' failed: Column names must be a identical to set {'mpg','disp'}, but is {'mpg','cyl','disp','hp','drat','wt','qsec','vs','am','gear','carb'}.
try(
pal::assert_cols(data = mtcars,
strict = TRUE)
)
#> Error in pal::assert_cols(data = mtcars, strict = TRUE) :
#> Assertion on 'mtcars' failed: Column names must be a identical to set {}, but is {'mpg','cyl','disp','hp','drat','wt','qsec','vs','am','gear','carb'}.