Function converts a gtsummary object to a flextable object. A user can use this function if they wish to add customized formatting available via the flextable functions. The flextable output is particularly useful when combined with R markdown with Word output, since the gt package does not support Word.
Usage
as_flex_table(x, include = everything(), return_calls = FALSE, ...)
Arguments
- x
(
gtsummary
)
An object of class"gtsummary"
- include
Commands to include in output. Input may be a vector of quoted or unquoted names. tidyselect and gtsummary select helper functions are also accepted. Default is
everything()
.- return_calls
Logical. Default is
FALSE
. IfTRUE
, the calls are returned as a list of expressions.- ...
Not used
Details
The as_flex_table()
function supports bold and italic markdown syntax in column headers
and spanning headers ('**'
and '_'
only).
Text wrapped in double stars ('**bold**'
) will be made bold, and text between single
underscores ('_italic_'
) will be made italic.
No other markdown syntax is supported and the double-star and underscore cannot be combined.
To further style your table, you may convert the table to flextable with
as_flex_table()
, then utilize any of the flextable functions.
Examples
trial |>
select(trt, age, grade) |>
tbl_summary(by = trt) |>
add_p() |>
as_flex_table()
Characteristic
Drug A
N = 981
Drug B
N = 1021
p-value2
Age
46 (37, 60)
48 (39, 56)
0.7
Unknown
7
4
Grade
0.9
I
35 (36%)
33 (32%)
II
32 (33%)
36 (35%)
III
31 (32%)
33 (32%)
1Median (Q1, Q3); n (%)
2Wilcoxon rank sum test; Pearson's Chi-squared test