yaml_agent_string: Display *pointblank* YAML using an agent or a YAML file

View source: R/yaml_write.R

yaml_agent_stringR Documentation

Display pointblank YAML using an agent or a YAML file

Description

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.

Usage

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.

filename

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.

path

An optional path to the YAML file (combined with filename).

expanded

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.

Examples

There's a YAML file available in the pointblank package that's called "agent-small_table.yml". The path for it can be accessed through system.file():

yml_file_path <- 
  system.file(
    "yaml", "agent-small_table.yml",
    package = "pointblank"
  )

We can view the contents of the YAML file in the console with the yaml_agent_string() function.

yaml_agent_string(filename = yml_file_path)
type: agent
tbl: ~ tbl_source("small_table", "tbl_store.yml")
tbl_name: small_table
label: A simple example with the `small_table`.
lang: en
locale: en
actions:
  warn_fraction: 0.1
  stop_fraction: 0.25
  notify_fraction: 0.35
steps:
- col_exists:
    columns: vars(date)
- col_exists:
    columns: vars(date_time)
- col_vals_regex:
    columns: vars(b)
    regex: '[0-9]-[a-z]{3}-[0-9]{3}'
- rows_distinct:
    columns: ~
- col_vals_gt:
    columns: vars(d)
    value: 100.0
- col_vals_lte:
    columns: vars(c)
    value: 5.0

Incidentally, we can also use yaml_agent_string() to print YAML in the console when supplying an agent object as the input. This can be useful for previewing YAML output just before writing it to disk with yaml_write().

Function ID

11-5

See Also

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


pointblank documentation built on April 25, 2023, 5:06 p.m.