Formats statistical tables (ANOVA, emmeans, etc.) for Quarto documents using knitr::kable() with pipe format. Produces clean output compatible with Quarto cross-references (@tbl-*) across HTML, PDF (Typst), and DOCX.

Uses the same column unification, formatting, and renaming pipeline as docx_tab(), but outputs a knitr_kable object instead of a flextable. Visual formatting (borders, font size, padding) is handled by the output template (e.g., reference.docx Table style), not inline.

bm_kable(
  x,
  lang = c("eng", "ger")[1],
  pvalform = "p.value",
  digits = "round_smart",
  add_abbrev_footnote = TRUE,
  align = NULL,
  as_kable = TRUE,
  verbose = FALSE,
  ...
)

Arguments

x

Table to be formatted (data.frame, tibble, anova, etc.)

lang

Language for column names. Either "eng" (default) or "ger".

pvalform

Names of columns formatted via format_p(). Default is "p.value". Set to NULL to skip p-value formatting.

digits

Number of digits for rounding. Default "round_smart" applies round_smart() per column. Can be a numeric value for fixed rounding.

add_abbrev_footnote

If TRUE (default), stores an abbreviation footnote as an attribute. Retrieve with bm_footnote().

align

Column alignment. NULL (default) auto-detects: numeric columns right-aligned, others left-aligned. Can be a character vector (e.g., c("l", "r", "r")).

as_kable

If TRUE (default), returns a knitr_kable object. If FALSE, returns the processed tibble.

verbose

If TRUE, prints transformation details. Default FALSE.

...

Other arguments passed to round_smart().

Value

A knitr_kable object (pipe format) when as_kable = TRUE, or a tibble when as_kable = FALSE. The kable object may have a "footnote" attribute containing abbreviation explanations.

See also

bm_footnote() to print the footnote, docx_tab() for flextable-based output (non-Quarto workflows).

Examples

library(BioMathR)

# Basic usage with ANOVA table
anova <- anova(lm(weight ~ group, data = PlantGrowth))
bm_kable(anova)
#> 
#> 
#> |Term      | df|   SS|  MS| F-value|p-value |
#> |:---------|--:|----:|---:|-------:|:-------|
#> |group     |  2|  3.8| 1.9|     4.8|0.016*  |
#> |Residuals | 27| 10.5| 0.4|      NA|        |
bm_kable(anova, lang = "ger")
#> 
#> 
#> |Term      | FG|   SQ|  MQ| F-Wert|p-Wert |
#> |:---------|--:|----:|---:|------:|:------|
#> |group     |  2|  3,8| 1,9|    4,8|0,016* |
#> |Residuals | 27| 10,5| 0,4|     NA|       |

# Return tibble instead of kable
bm_kable(anova, as_kable = FALSE)
#> # A tibble: 2 × 6
#>   Term         df    SS    MS `F-value` `p-value`
#>   <chr>     <int> <dbl> <dbl>     <dbl> <chr>    
#> 1 group         2   3.8   1.9       4.8 "0.016*" 
#> 2 Residuals    27  10.5   0.4      NA   ""       

# Footnote retrieval
tab <- bm_kable(anova)
bm_footnote(tab)
#> [1] "*df = degrees of freedom; SS = sum of squares; MS = mean squares*"
#> attr(,"class")
#> [1] "knit_asis"
#> attr(,"knit_cacheable")
#> [1] NA

# Custom alignment
bm_kable(anova, align = c("l", "r", "r", "r", "r", "r"))
#> 
#> 
#> |Term      | df|   SS|  MS| F-value| p-value|
#> |:---------|--:|----:|---:|-------:|-------:|
#> |group     |  2|  3.8| 1.9|     4.8|  0.016*|
#> |Residuals | 27| 10.5| 0.4|      NA|        |