Given an informant object, update and incorporate table snippets
Given an informant object, update and incorporate table snippets
When the informant object has a number of snippets available (by using info_snippet()) and the strings to use them (by using the info_*()
functions and {<snippet_name>} in the text elements), the process of incorporating aspects of the table into the info text can occur by using the incorporate() function. After that, the information will be fully updated (getting the current state of table dimensions, re-rendering the info text, etc.) and we can print the informant object or use the get_informant_report() function to see the information report.
incorporate(informant)
Arguments
informant: The pointblank informant object
obj:<ptblank_informant> // required
A pointblank informant object that is commonly created through the use of the create_informant() function.
Returns
A ptblank_informant object.
Examples
Take the small_table and assign it to changing_table (we'll modify it later):
Use create_informant() to generate an informant object with changing_table given to the tbl argument with a leading ~ (ensures that the table will be fetched each time it is needed, instead of being statically stored in the object). We'll add two snippets with info_snippet(), add information with the info_columns() and info_section() functions and then use incorporate() to work the snippets into the info text.
informant <-
create_informant(
tbl = ~ changing_table,
tbl_name = "changing_table",
label = "`informant()` example"
) %>%
info_snippet(
snippet_name = "row_count",
fn = ~ . %>% nrow()
) %>%
info_snippet(
snippet_name = "col_count",
fn = ~ . %>% ncol()
) %>%
info_columns(
columns = a,
info = "In the range of 1 to 10. ((SIMPLE))"
) %>%
info_columns(
columns = starts_with("date"),
info = "Time-based values (e.g., `Sys.time()`)."
) %>%
info_columns(
columns = date,
info = "The date part of `date_time`. ((CALC))"
) %>%
info_section(
section_name = "rows",
row_count = "There are {row_count} rows available."
) %>%
incorporate()
We can print the resulting object to see the information report.
informant
Let's modify test_table to give it more rows and an extra column.
changing_table <-
dplyr::bind_rows(changing_table, changing_table) %>%
dplyr::mutate(h = a + c)
Using incorporate() will cause the snippets to be reprocessed and
accordingly the content of the report will be updated to keep up with the
current state of the changing_table.
informant <- informant %>% incorporate()
When printed again, we'll also see that the row and column counts in the
header have been updated to reflect the new dimensions of the target table.
Furthermore, the info text in the ROWS section has updated text
("There are 26 rows available.").
informant
Function ID
7-1
See Also
Other Incorporate and Report: get_informant_report()