Translates a table created with tablespan to a flextable. See <https://ardata-fr.github.io/flextable-book/>.
Usage
# S3 method for class 'Tablespan'
as_flextable(x, theme = flextable::theme_booktabs, ...)Details
Flextable is an extremely versatile table creator for R with great support to export to a variety of formats.
Examples
library(tablespan)
library(dplyr)
data("mtcars")
summarized_table <- mtcars |>
group_by(cyl, vs) |>
summarise(N = n(),
mean_hp = mean(hp),
sd_hp = sd(hp),
mean_wt = mean(wt),
sd_wt = sd(wt))
#> `summarise()` has grouped output by 'cyl'. You can override using the `.groups`
#> argument.
tbl <- tablespan(data = summarized_table,
formula = (LHS = Cylinder:cyl + Engine:vs) ~
N +
(Results = (`Horse Power` = Mean:mean_hp + SD:sd_hp) +
(`Weight` = Mean:mean_wt + SD:sd_wt)))
if(require_flextable(throw = FALSE)){
library(flextable)
flex_tbl <- as_flextable(tbl)
flex_tbl
}
Results
LHS
Horse Power
Weight
Cylinder
Engine
N
Mean
SD
Mean
SD
4
0
1
91.00
2.1400
4
1
10
81.80
21.872
2.3003
0.60
6
0
3
131.67
37.528
2.7550
0.13
6
1
4
115.25
9.179
3.3887
0.12
8
0
14
209.21
50.977
3.9992
0.76