# The `small_table` dataset in the
# package has an `e` column which has
# logical values; the following examples
# will validate that that column is of
# the `logical` class
# A: Using an `agent` with validation
# functions and then `interrogate()`
# Validate that the column `e` has the
# `logical` class
agent <-
create_agent(small_table) %>%
col_is_logical(vars(e)) %>%
interrogate()
# Determine if this validation
# had no failing test units (1)
all_passed(agent)
# Calling `agent` in the console
# prints the agent's report; but we
# can get a `gt_tbl` object directly
# with `get_agent_report(agent)`
# B: Using the validation function
# directly on the data (no `agent`)
# This way of using validation functions
# acts as a data filter: data is passed
# through but should `stop()` if there
# is a single test unit failing; the
# behavior of side effects can be
# customized with the `actions` option
small_table %>%
col_is_logical(vars(e)) %>%
dplyr::slice(1:5)
# C: Using the expectation function
# With the `expect_*()` form, we would
# typically perform one validation at a
# time; this is primarily used in
# testthat tests
expect_col_is_logical(
small_table, vars(e)
)
# D: Using the test function
# With the `test_*()` form, we should
# get a single logical value returned
# to us
small_table %>%
test_col_is_logical(vars(e))
Run the code above in your browser using DataLab