# NOT RUN {
library(dplyr)
# Create a simple data frame with
# a column of numerical values
tbl <- tibble(a = c(5, 7, 8, 5))
# Create an `action_levels()` list
# with fractional values for the
# `warn`, `stop`, and `notify` states
al <-
action_levels(
warn_at = 0.2,
stop_at = 0.8,
notify_at = 0.345
)
# Validate that values in column
# `a` are always greater than 7 and
# apply the list of action levels
agent <-
create_agent(tbl = tbl) %>%
col_vals_gt(vars(a), 7, actions = al) %>%
interrogate()
# The report from the agent will show
# that the `warn` state has been entered
# for the first and only validation step.
agent %>%
get_agent_report(display_table = FALSE)
# In the context of using validation
# stop functions directly on data, their
# use is commonly to trigger warnings
# and raise errors. The following will
# provide a warning (but that's suppressed
# here).
suppressWarnings(
tbl %>%
col_vals_gt(vars(a), 5, actions = al)
)
# }
Run the code above in your browser using DataLab