Skip to contents

The tbl_source() function provides a convenient means to access a table-prep formula from either a tbl_store object or a table store YAML file (which can be created with the yaml_write() function). A call to tbl_source() is most useful as an input to the tbl argument of create_agent(), create_informant(), or set_tbl().

Should you need to obtain the table itself (that is generated via the table-prep formula), then the tbl_get() function should be used for that.


tbl_source(tbl, store = NULL)



The table name associated with a table-prep formula. This is part of the table store. This table could be identified by its name (e.g., tbl = "large_table") or by supplying a reference using a subset (with $) of the tbl_store object (e.g., tbl = store$large_table). If using the latter method then nothing needs to be supplied to store.


Either a table store object created by the tbl_store() function or a path to a table store YAML file created by yaml_write().


A table-prep formula.


Let's create a tbl_store object by giving two table-prep formulas to tbl_store().

store <- 
    small_table_duck ~ db_tbl(
      table = small_table,
      dbname = ":memory:",
      dbtype = "duckdb"
    sml_table ~ pointblank::small_table

We can pass a table-prep formula to create_agent() via tbl_source(), add some validation steps, and interrogate the table shortly thereafter.

agent_1 <- 
    tbl = ~ tbl_source("sml_table", store),
    label = "`tbl_source()` example",
    actions = action_levels(warn_at = 0.10)
  ) %>% 
  col_exists(columns = c(date, date_time)) %>%

The agent_1 object can be printed to see the validation report in the Viewer.


This image was generated from the first code example in the `tbl_source()` help file.

The tbl_store object can be transformed to YAML with the yaml_write() function. The following statement writes the tbl_store.yml file by default (but a different name could be used with the filename argument):


Let's modify the agent's target to point to the table labeled as "sml_table" in the YAML representation of the tbl_store.

agent_2 <-
  agent_1 %>% 
    ~ tbl_source(
        tbl = "sml_table",
        store = "tbl_store.yml"

We can likewise write the agent to a YAML file with yaml_write() (writes to agent-sml_table.yml by default but the filename allows for any filename you want).


Now that both the agent and the associated table store are present as on-disk YAML, interrogations can be done by using yaml_agent_interrogate().

agent <- yaml_agent_interrogate(filename = "agent-sml_table.yml")

Function ID


See also