Skip to contents

Render supported gtstats objects as formatted gt tables.

Usage

to_gt(
  x,
  title = NULL,
  subtitle = NULL,
  bold_labels = TRUE,
  show_footnotes = TRUE
)

Arguments

x

A supported gtstats object.

title

Optional table title.

subtitle

Optional table subtitle.

bold_labels

Logical; whether to bold variable labels where appropriate.

show_footnotes

Logical; whether explanatory footnotes should be displayed.

Value

A gt_tbl object.

Details

This function is the explicit rendering bridge between analytical gtstats objects and presentation-ready table output. It supports descriptive, inferential, epidemiological, and table-builder objects created by the package and applies a consistent visual style using gt.

Supported inputs include:

  • gt_describe

  • gt_distribution

  • gt_variance

  • gt_compare

  • gt_correlation

  • gt_effect

  • gt_prop

  • gt_rate

  • gt_twobytwo

  • gtstats_summary

  • gt_data_table

Examples

to_gt(describe_data(mtcars))
Variable Type Complete Unique Overview Range / levels
mpg continuous 32/32 (100.0%) 25 Mean 20.09 (SD 6.03); median 19.20 10.40 to 33.90
cyl categorical 32/32 (100.0%) 3 8 14 (43.8%); 4 11 (34.4%); 6 7 (21.9%) 6, 4, 8
disp continuous 32/32 (100.0%) 27 Mean 230.72 (SD 123.94); median 196.30 71.10 to 472.00
hp continuous 32/32 (100.0%) 22 Mean 146.69 (SD 68.56); median 123.00 52.00 to 335.00
drat continuous 32/32 (100.0%) 22 Mean 3.60 (SD 0.53); median 3.70 2.76 to 4.93
wt continuous 32/32 (100.0%) 29 Mean 3.22 (SD 0.98); median 3.33 1.51 to 5.42
qsec continuous 32/32 (100.0%) 30 Mean 17.85 (SD 1.79); median 17.71 14.50 to 22.90
vs binary 32/32 (100.0%) 2 0 18 (56.2%); 1 14 (43.8%) 0, 1
am binary 32/32 (100.0%) 2 0 19 (59.4%); 1 13 (40.6%) 1, 0
gear categorical* 32/32 (100.0%) 3 3 15 (46.9%); 4 12 (37.5%); 5 5 (15.6%) 4, 3, 5
carb continuous 32/32 (100.0%) 6 Mean 2.81 (SD 1.62); median 2.00 1.00 to 8.00
* Possible ordinal or count-coded variable. Confirm the intended meaning and order using the data dictionary or clinical context.
to_gt(summary_table(mtcars, by = am, include = c(mpg, wt)))
Characteristic1 1
N = 13
1
0
N = 19
1
mpg 24.4 (6.2) 17.1 (3.8)
wt 2.4 (0.6) 3.8 (0.8)
1 Continuous data are mean (SD).
to_gt(compare_groups(mtcars, variable = mpg, group = am))
Variable 0
N = 19
1
N = 13
Mean difference (95% CI)1 p-value2
mpg 17.15 (3.83) 24.39 (6.17) -7.24 (-11.28 to -3.21) <0.01
1 Difference is 0 minus 1.
2 Welch t-test
to_gt( summary_table( mtcars, by = am, include = c(mpg, wt, cyl), overall = TRUE ) |> add_total() |> add_p() )
Characteristic1 Overall
N = 32
1
1
N = 13
1
0
N = 19
1
p-value2
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
1 Continuous data are mean (SD). Categorical data are n (%).
2 ᵃ Welch t-test; ᵇ Fisher's exact test (Monte Carlo p-value)