I am trying to export two (flex)tables within the same word document. Here what I have:
df1 <- data.frame(a = 1:3, b = 1:3)
df2 <- data.frame(c = 11:13, d = 11:13)
library(flextable)
df1_ft <- regulartable(df1)
df2_ft <- regulartable(df2)
library(officer)
word_export <- read_docx()
word_export <- body_add_flextable(word_export, df1_ft)
word_export <- body_add_flextable(word_export, df2_ft)
print(word_export, 'try.docx')
Yet, the results is a single table containing both tables. Any idea how I can add to two tables one after the other?
The two tables are being output to Word one after the other, and as there are no line breaks between them they appear as one. Simplest solution is to place a paragraph with empty text between them:
word_export <- read_docx()
body_add_flextable(word_export, df1_ft)
body_add_par(word_export, value = "")
body_add_flextable(word_export, df2_ft)
print(word_export, 'try.docx')
You can also see that you don't need to repeatedly assign the output of each body_add_*
line back to your word_export file - the Word file is updated directly by each call.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With