library(officer)
ctl = list(iris2=crosstable(iris2, 1),
"Just a flextable"=flextable::flextable(mtcars2[1:5,1:5]),
"Just a dataframe"=iris2[1:5,1:5])
fun1 = function(doc, .name){
doc %>%
body_add_title(" This is table '{.name}' as a flex/crosstable", level=2) %>%
body_add_normal("Here is the table:")
}
fun2 = function(doc, .name){
doc %>% body_add_table_legend("{.name}", bookmark=.name)
}
read_docx() %>%
body_add_title("Separated by subtitle", 1) %>%
body_add_table_list(ctl, fun_before="title2") %>%
body_add_break() %>%
body_add_title("Separated using a custom function", 1) %>%
body_add_normal("You can therefore use bookmarks, for instance here are
tables \\@ref(iris2), \\@ref(just_a_flextable)
and \\@ref(just_a_dataframe).") %>%
body_add_table_list(ctl, fun_before=fun1, fun_after=fun2, body_fontsize=8) %>%
write_and_open()
Run the code above in your browser using DataLab