I am trying to create a Microsoft Word document table using the R
flextable
package.
My attempt:
library(flextable)
library(dplyr)
# create flextables
Outer_table <- data.frame(Number = c(1,2),
table = c(NA,NA)) %>% flextable()
df1 <- data.frame(Species = c("Maple", "Oak", "Hemlock", "Red Pine"),
Age = c(40,37,52,64)) %>% flextable()
# combine flextables
Outer_table <- Outer_table %>%
flextable::compose(j ="Table", i = 1,value = df1)
This results in an error
Error in x$data[i,j] <- value: number of items to replace is not a multible of replacement length.
- What would be a way of properly fomrating the smaler dfs to create a table such as this?
- Additionaly, how would I go about adding in the text "Table of Average Tree Ages by Species" above the table?
Maybe, this gets you started. I think
{officer}
offers help:I expect that further styling can be achieved with
body_add_*()
-functions, see here.