# NOT RUN {
# Create a simple table with two
# columns of numerical values
tbl <-
dplyr::tibble(
a = c(5, 7, 6, 5, 8, 7),
b = c(7, 1, 0, 0, 0, 3)
)
# Create an `action_levels()` list
# with absolute values for the
# `warn`, and `notify` states (with
# thresholds of 1 and 2 'fail' units)
al <-
action_levels(
warn_at = 1,
notify_at = 2
)
# Validate that values in column
# `a` from `tbl` are always > 5 and
# that `b` values are always < 5;
# first, apply the `actions_levels()`
# directive to `actions` and set up
# an `email_blast()` as one of the
# `end_fns` (by default, the email
# will be sent if there is a single
# 'notify' state across all
# validation steps)
# agent <-
# create_agent(
# tbl = tbl,
# actions = al,
# end_fns = list(
# ~ email_blast(
# x,
# to = "joe_public@example.com",
# from = "pb_notif@example.com",
# msg_subject = "Table Validation",
# credentials = blastula::creds_key(
# id = "gmail"
# ),
# )
# )
# ) %>%
# col_vals_gt(vars(a), 5) %>%
# col_vals_lt(vars(b), 5) %>%
# interrogate()
# This example was intentionally
# not run because email credentials
# aren't available and the `to`
# and `from` email addresses are
# nonexistent; to look at the email
# message before sending anything of
# the like, we can use the
# `email_preview()` function
email_object <-
create_agent(
tbl = tbl,
actions = al
) %>%
col_vals_gt(vars(a), 5) %>%
col_vals_lt(vars(b), 5) %>%
interrogate() %>%
email_preview()
# }
Run the code above in your browser using DataLab