tabulator object can be transformed as a flextable with method as_flextable().

# S3 method for tabulator
as_flextable(
  x,
  separate_with = character(0),
  big_border = fp_border_default(width = 1.5),
  small_border = fp_border_default(width = 0.75),
  rows_alignment = "left",
  columns_alignment = "center",
  label_rows = x$rows,
  spread_first_col = FALSE,
  sep_w = 0.05,
  unit = "in",
  ...
)

Arguments

x

result from tabulator()

separate_with

columns used to sepatate the groups with an horizontal line.

big_border, small_border

big and small border properties defined by a call to fp_border_default() or fp_border().

rows_alignment, columns_alignment

alignments to apply to columns corresponding to rows and columns; see arguments rows and columns in tabulator().

label_rows

labels to use for the first column names, i.e. the row column names. It must be a named vector, the values will be matched based on the names.

spread_first_col

if TRUE, first row is spread as a new line separator instead of being a column. This helps to reduce the width and allows for clear divisions.

sep_w

blank column separators'width to be used. If 0, blank column separators will not be used.

unit

unit of argument sep_w, one of "in", "cm", "mm".

...

unused argument

Examples

library(flextable)

set_flextable_defaults(digits = 2, border.color = "gray")

if(require("stats")){
  dat <- aggregate(breaks ~ wool + tension,
    data = warpbreaks, mean)

  cft_1 <- tabulator(x = dat,
                     rows = "wool",
    columns = "tension",
    `mean` = as_paragraph(as_chunk(breaks)),
    `(N)` = as_paragraph(
      as_chunk(length(breaks) ))
  )

  ft_1 <- as_flextable(cft_1, sep_w = .1)
  ft_1

  set_flextable_defaults(padding = 1, font.size = 9, border.color = "orange")
  ft_2 <- as_flextable(cft_1, sep_w = 0)
  ft_2

  set_flextable_defaults(padding = 6, font.size = 11,
                         border.color = "white", font.color = "white",
                         background.color = "#333333")
  ft_3 <- as_flextable(
    x = cft_1, sep_w = 0,
    rows_alignment = "center",
    columns_alignment = "right")
  ft_3
}
#> a flextable object.
#> col_keys: `wool`, `@L@mean`, `@L@(N)`, `@M@mean`, `@M@(N)`, `@H@mean`, `@H@(N)` 
#> header has 2 row(s) 
#> body has 2 row(s) 
#> original dataset sample: 
#>   wool breaks@L breaks@M breaks@H mean@L mean@M mean@H (N)@L (N)@M (N)@H
#> 1    A 44.55556 24.00000 24.55556                                       
#> 2    B 28.22222 28.77778 18.77778                                       
#>   @L@mean @L@(N) @M@mean @M@(N) @H@mean @H@(N)
#> 1                                             
#> 2                                             

init_flextable_defaults()