-1

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?

5
  • 1
    Get it before! Just take df. flextable() expects data as first argument, so you can access the data in your workflow before creating a flextable. Commented Aug 30 at 17:04
  • Why do you want to convert the flextable back? Commented Aug 30 at 18:01
  • @TimG Because I'm going to post-process it in a pipe and I need the data of the original dataframe in the post-processing phase, and I don't like passing it over Commented Aug 30 at 18:10
  • 5
    This neither sounds necessary nor senseful. I think you are running an XY problem, please show the workflow. Commented Aug 30 at 18:52
  • 3
    The suggested answer is a little insightful to me (about 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? Commented Aug 30 at 19:29

1 Answer 1

3

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.