Replies: 5 comments 12 replies
-
Hi @pteridin , I agree, but something like this is more of a task for The linked example should still work, but it is slow, because we have to parse the entire Finally, since I use neither |
Beta Was this translation helpful? Give feedback.
-
I have moved this to a discussion, because as stated, I do not see this as an issue with |
Beta Was this translation helpful? Give feedback.
-
![]() Ah it's fun, here is the update with headers. And I made minor improvements to the code snippet. There is But now I'm leaving this to you :) # source wb_add_flextable() function
source("https://gist.githubusercontent.com/JanMarvin/1107238d9a07acba8fb1b3f88af618ad/raw/fba7170f9b0d566432995e25e0a282b5d53b5325/flextable_fancy.R")
library(tidyr)
library(gtsummary)
library(openxlsx2)
ft_base <- as_tibble(Titanic) |>
uncount(n) |>
tbl_strata(strata = Class,
.tbl_fun = \(x) {
x |>
tbl_summary(by=Sex) |>
add_difference(everything() ~ "smd")
}) |>
bold_labels() |>
italicize_levels() |>
as_flex_table()
wb_workbook() |>
wb_add_worksheet() |>
wb_add_flextable(ft = ft_base) |>
wb_open() |
Beta Was this translation helpful? Give feedback.
-
Hello there! Progress is made, output for gtsummary-flextables looks nice and is somewhat more performant to the previous implementation. Though, I guess there is still room for improvement and test tables needed to see if the output matches the expected output. I already tested the following table that came out messed up. Probably - again - an issue with the merging and applying the respective styling. flextable::as_flextable(table(mtcars[,1:2])) To make testing the changes easier I integrated it into openxlsx2 (Link) and I would plan to merge it into openxls2 if more testing is done. Most of the code is still your implementation @JanMarvin and I think it would fit this package better than flextable. It would also be a push to make openxlsx2 more relevant to all those data analysts out there that need to poop out tables as much as I do. Edit: Repo not longer available. See next post. |
Beta Was this translation helpful? Give feedback.
-
Long story short: Here it is Package Link - a beautiful composition of new pipes and much more dplyr-dependencies then I would like. But at least with a more correct output. :) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
It would be lovely to have the option to export gtsummary / flextable objects into excel retaining the style and (all) header and footer lines.
In my workplace lots of gtsummary-objects are created. Usually I convert the gtsummary-object to a tibble and export it using openxlsx/openxlsx2. This could be a minimal viable option if it would retain all the strata headers - though it doesn't retain it. A wrapper to correctly export the table into excel - from gtsummary and/or flextable - would be quite nice.
Example
Beta Was this translation helpful? Give feedback.
All reactions