Add a section with a table and its legend
a rdocx object
a table: crosstable, flextable, or plain old dataframe
the legend to use
passed on to flextable::body_add_flextable() or body_add_crosstable()
the bookmark to use. Defaults to the cleaned variable name of x
the title to add for the section. Can also be FALSE (no title) or TRUE (the title defaults to legend)
the title level if applicable
a sentence to add between the title (if applicable) and the table. If TRUE, defaults to "Information about {tolower(title)} is described in Table @ref({bookmark})".
The docx object doc
library(officer)
read_docx() %>%
body_add_title("Description", 1) %>%
body_add_title("Population A", 2) %>%
body_add_table_section(head(iris), "The iris dataset", sentence=TRUE) %>%
body_add_table_section(crosstable(iris), "A crosstable of the iris dataset",
title=FALSE, sentence=TRUE, body_fontsize=8) %>%
write_and_open()