I'm working on generating a document for which I need to provide a single table broken up into many smaller tables for a word document. I figured this might be a good place to use flextable and purrr. However, the output is bedeviling me, and I just don't get tables. Let's assume I'm setup for an rmarkdown document. I have the document setup for word output, and then attempt the following:
YAML:
---
title: "PURRR and tables for word"
output: word_document
---
Here's the setup code block:
#libraries
library(knitr)
library(purrr)
library(flextable)
#the table
my_tab <- tibble::tribble(
~`Biogenic.Habitat/Species`, ~Limiting.Driver, ~`Max,.Min,.or.Mean`, ~Units, ~Value,
"Clams", "Flow Velocity", "Min", "m/s", 0.04,
"Mussel Bed", "Depth", "Max", "m", 10,
"Mussel Bed", "Flow Velocity", "Max", "m/s", 1.8,
"Mussel Bed", "Temperature", "Max", "C", 32,
"Oysters", "Flow Velocity", "Max", "m/s", 2.6,
"Oysters", "Flow Velocity", "Min", "m/s", 1.56)
#split it to a list
my_tab_split <- my_tab %>% split(.$`Biogenic.Habitat/Species`)
So far, so good.
Now, the following works in my markdown document and outputs a nice table.
regulartable(my_tab)
But, the following code just outputs either nothing, lists, or codes
#generates nothing
walk(my_tab_split, regulartable)
#generates nothing
walk(my_tab_split, ~regulartable(.x) %>% knit_print())
#generates the original list
map(my_tab_split, ~regulartable(.x))
#generates word code
map(my_tab_split, ~regulartable(.x) %>% knit_print())
Nor does the following work.
for(i in 1:length(my_tab_split)){
regulartable(my_tab_split[[i]]) %>% knit_print()
}
Any thoughts on how to make purrr and flextable make beautiful music together in a word doc?