Translates a table created with tablespan to a great table (gt). See <https://gt.rstudio.com/>.
Arguments
- tbl
table created with tablespan::tablespan
- groupname_col
Provide column names to group data. See ?gt::gt for more details.
- separator_style
style of the vertical line that separates the row names from the data.
- auto_format
should the table be formatted automatically?
- ...
additional arguments passed to gt::gt().
Details
Tablespan itself does not provide any printing of tables as HTML table. However, with as_gt, tablespan can be translated to a great table which provides html and LaTeX output.
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 regrouped the output.
#> ℹ Summaries were computed grouped by cyl and vs.
#> ℹ Output is grouped by cyl.
#> ℹ Use `summarise(.groups = "drop_last")` to silence this message.
#> ℹ Use `summarise(.by = c(cyl, vs))` for per-operation grouping
#> (`?dplyr::dplyr_by`) instead.
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_gt(throw = FALSE)){
gt_tbl <- as_gt(tbl)
gt_tbl
}