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.
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 thetbl_store
object (e.g.,tbl = store$large_table
). If using the latter method then nothing needs to be supplied tostore
.- store
Either a table store object created by the
tbl_store()
function or a path to a table store YAML file created byyaml_write()
.
Examples
Let's create a tbl_store
object by giving two table-prep formulas to
tbl_store()
.
store <-
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()
via tbl_source()
, add
some validation steps, and interrogate the table shortly thereafter.
agent_1 <-
create_agent(
tbl = ~ tbl_source("sml_table", store),
label = "`tbl_source()` example",
actions = action_levels(warn_at = 0.10)
) %>%
col_exists(columns = c(date, date_time)) %>%
interrogate()
The agent_1
object can be printed to see the validation report in the
Viewer.
agent_1
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):
yaml_write(store)
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 %>%
set_tbl(
~ 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).
yaml_write(agent_2)
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")
See also
Other Planning and Prep:
action_levels()
,
create_agent()
,
create_informant()
,
db_tbl()
,
draft_validation()
,
file_tbl()
,
scan_data()
,
tbl_get()
,
tbl_store()
,
validate_rmd()