# NOT RUN {
# 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
)
if (interactive()) {
# Validate that values in column
# `a` from `small_tbl` are always > 1
# and that they are always < 7; 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(
read_fn = ~ small_table,
tbl_name = "small_table",
label = "An example.",
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 = "smtp2go"
),
)
)
) %>%
col_vals_gt(vars(a), value = 1) %>%
col_vals_lt(vars(a), value = 7) %>%
interrogate()
}
# The above example was intentionally
# not run because email credentials
# aren't available and the `to`
# and `from` email addresses are
# nonexistent
# To get a blastula email object
# instead of eagerly sending the
# message, we can use the
# `email_create()` function
email_object <-
create_agent(
read_fn = ~ small_table,
tbl_name = "small_table",
label = "An example.",
actions = al
) %>%
col_vals_gt(vars(a), value = 5) %>%
col_vals_lt(vars(a), value = 7) %>%
interrogate() %>%
email_create()
# }
Run the code above in your browser using DataLab