With pointblank YAML, we can serialize an agent's validation plan (with yaml_write()), read it back later with a new agent (with yaml_read_agent()), or perform an interrogation on the target data table directly with the YAML file (with yaml_agent_interrogate()). The yaml_agent_string() function allows us to inspect the YAML generated by yaml_write() in the console, giving us a look at the YAML without needing to open the file directly. Alternatively, we can provide an agent to the yaml_agent_string() and view the YAML representation of the validation plan without needing to write the YAML to disk beforehand.

yaml_agent_string(agent = NULL, filename = NULL, path = NULL, expanded = FALSE)

## Arguments

agent An agent object of class ptblank_agent. If an object is provided here, then filename must not be provided. The name of the YAML file that contains fields related to an agent. If a file name is provided here, then agent object must not be provided in agent. An optional path to the YAML file (combined with filename). Should the written validation expressions for an agent be expanded such that tidyselect and vars() expressions for columns are evaluated, yielding a validation function per column? By default, this is FALSE so expressions as written will be retained in the YAML representation.

## Function ID

11-5

Other pointblank YAML: yaml_agent_interrogate(), yaml_agent_show_exprs(), yaml_exec(), yaml_informant_incorporate(), yaml_read_agent(), yaml_read_informant(), yaml_write()

## Examples

if (interactive()) {

# Let's create a validation plan for the
# data quality analysis of the small_table
# dataset; we need an agent and its
# table-prep formula enables retrieval
# of the target table
agent <-
create_agent(
label = "A simple example with the small_table.",
actions = action_levels(
warn_at = 0.10,
stop_at = 0.25,
notify_at = 0.35
)
) %>%
col_exists(vars(date, date_time)) %>%
col_vals_regex(
vars(b),
regex = "[0-9]-[a-z]{3}-[0-9]{3}"
) %>%
rows_distinct() %>%
col_vals_gt(vars(d), value = 100) %>%
col_vals_lte(vars(c), value = 5)

# We can view the YAML file in the console
# with the yaml_agent_string() function,
# providing the agent object as the input
yaml_agent_string(agent = agent)

# The agent can be written to a pointblank
# YAML file with yaml_write()
yaml_write(
agent = agent,
filename = "agent-small_table.yml"
)

# The 'agent-small_table.yml' file is
# available in the package through
# system.file()
yml_file <-
system.file(
"yaml", "agent-small_table.yml",
package = "pointblank"
)

# The yaml_agent_string() function can
# be used with the YAML file as well
yaml_agent_string(filename = yml_file)

# At a later time, the YAML file can
# be read into a new agent with the
# yaml_read_agent() function