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 read_fn argument of create_agent(), create_informant(), or set_read_fn().

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)

Arguments

tbl

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.

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().

Value

A table-prep formula.

Function ID

1-9

See also

Examples

if (interactive()) {

# Let's create a `tbl_store` object by
# giving two table-prep formulas to
# `tbl_store()`
tbls <- 
  tbl_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()` and interrogate
# the table shortly thereafter
agent <- 
  create_agent(
    read_fn = ~ tbl_source("sml_table", tbls),
    label = "An example that uses a table store.",
    actions = action_levels(warn_at = 0.10)
  ) %>% 
  col_exists(vars(date, date_time)) %>%
  interrogate()

# Both the `tbl_store` object and the
# `agent` can be transformed to YAML with
# the `yaml_write()` function

# This writes the `tbl_store.yml` file
# by default (but a different name
# could be used)
yaml_write(tbls)

# Let's modify the agent's `read_fn` to point
# to the YAML representation of the `tbl_store`
agent <-
  agent %>% 
  set_read_fn(
    ~ tbl_source(
        tbl = "sml_table",
        store = "tbl_store.yml"
      )
  )

# Then we can write agent to a YAML
# file (writes to `agent-sml_table.yml`
# by default)
yaml_write(agent)

# Now that both are in this on-disk format
# an interrogation can be done by accessing
# the agent YAML
agent <-
  yaml_agent_interrogate(
    filename = "agent-sml_table.yml"
  )

}