Skip to contents

Convert a supported gtstats object into a flextable for use in Word, PowerPoint, and other Office-style outputs.

Usage

to_flextable(
  x,
  font_size = 10,
  font = NULL,
  autofit = TRUE,
  show_footnotes = TRUE,
  title = NULL,
  subtitle = NULL
)

Arguments

x

A supported gtstats object containing a $table component, such as an object returned by summary_table(), compare_groups(), proportion_stats(), as_stats_table(), or related functions.

font_size

Font size applied to the whole table. Default is 10.

font

Optional font family applied to the whole table.

autofit

Logical; whether column widths should be adjusted automatically using flextable::autofit().

show_footnotes

Logical; include concise explanatory footnotes.

title, subtitle

Optional title and subtitle placed above the table.

Value

A flextable object.

Details

This function is intended for export workflows where a gtstats object needs to be inserted into a report or presentation. The input should be the original analytical object, not the rendered gt table returned by to_gt().

Text columns are left-aligned and value columns are right-aligned. Notes, footnotes, and p-value method footnotes are appended to the footer when available.

Examples

res <- summary_table(mtcars, by = am, overall = TRUE) |>
  add_summary(vars = c(mpg, wt, cyl)) |>
  add_total() |>
  add_p()

to_flextable(res)

Characteristic

Overall
N = 32

1
N = 13

0
N = 19

p-value

mpg

20.1 (6.0)

24.4 (6.2)

17.1 (3.8)

0.001ᵃ

wt

3.2 (1.0)

2.4 (0.6)

3.8 (0.8)

<0.001ᵃ

cyl

0.007ᵇ

4

11 (34.4%)

8 (61.5%)

3 (15.8%)

6

7 (21.9%)

3 (23.1%)

4 (21.1%)

8

14 (43.8%)

2 (15.4%)

12 (63.2%)

Total (N)

32

13

19

Continuous data are mean (SD). Categorical data are n (%).

ᵃ Welch t-test; ᵇ Fisher's exact test (Monte Carlo p-value)