library(officer)
library(crosstable)
info_rows = c("Also, table iris has {nrow(iris)} rows.",
"And table mtcars has {nrow(mtcars)} rows.")
doc = read_docx() %>%
body_add_normal("Table iris has", ncol(iris), "columns.", .sep=" ") %>% #paste style
body_add_normal("However, table mtcars has {ncol(mtcars)} columns") %>% #glue style
body_add_normal(info_rows) %>% #vector style
body_add_normal("")
doc = doc %>%
body_add_normal("You can write text in *italic1*, _underlined1_, **bold1**, and `code`,
and you can also add * **references** *, for instance a ref to Table
@ref(my_table). Multiple spaces are ignored (squished) so that you
can enter multiline text.") %>%
body_add_normal() %>%
body_add_normal("Here I should use `body_add_crosstable()` to add a table before the
legend.") %>%
body_add_table_legend("My pretty table", bookmark="my_table")
write_and_open(doc)
#Markdown support
read_docx() %>%
body_add_normal("This is **bold and *italic* (see Table @ref(my_bkm)). ** This is
**bold `console \\*CODE\\*` and *bold _and_ italic* **") %>%
body_add_normal("This is red **bold** text, this is ~subscript *italic*~,
and this is ^superscript with yellow^") %>%
body_add_normal("This is a fancy font and this `is code`!!") %>%
#you might need to change "Alibi" to "alibi" here
body_add_normal() %>%
body_add_table_legend("Some table legend", bookmark="my_bkm") %>%
write_and_open()
Run the code above in your browser using DataLab