After something like:
library(tidyverse)
df <- tibble(a=c(1,2,3), b=c(4,5,6))
tbl <- df %>% flextable::flextable()
Is there a way to get back df from tbl?
There is no built-in function or way to convert a flextable to a dataframe. You may extract the data from the tbl through the 'body' of the 'x' component (contains most of the data used to create the table) of the object.
Once extracted, convert the data back to a df.
It can be done like:
df_new <- as_tibble(tbl$body$dataset)
df.flextable()expectsdataas first argument, so you can access the data in your workflow before creating aflextable.tbl$body$dataset), but frankly I find it only useful if you made the flextable object and forgot to save your original dataset. If you do something in flextable-speak that generates a much-different table that is not similar enough to the original, then either (a) you're doing something with flextable I'm not familiar with, or (b) you're trying to capture something that is not inherently supported in R's frames, such as multi-headers, merged-cells, etc. Can you expand your example to better highlight what you need?