as_hux_table: Convert gtsummary object to a huxtable object

View source: R/as_hux_table.R

as_hux_tableR Documentation

Convert gtsummary object to a huxtable object

Description

Function converts a gtsummary object to a huxtable object. A user can use this function if they wish to add customized formatting available via the huxtable functions. The huxtable package supports output to PDF via LaTeX, as well as HTML and Word.

Usage

as_hux_table(x, include = everything(), return_calls = FALSE)

as_hux_xlsx(x, file, include = everything(), bold_header_rows = TRUE)

Arguments

x

(gtsummary or list)
a gtsummary object, or a (optionally named) list of gtsummary objects. When a list is passed to as_hux_xlsx(), each table is written to its own worksheet and the list names are used as the worksheet names.

include

Commands to include in output. Input may be a vector of quoted or unquoted names. tidyselect and gtsummary select helper functions are also accepted. Default is everything().

return_calls

Logical. Default is FALSE. If TRUE, the calls are returned as a list of expressions.

file

File path for the output.

bold_header_rows

(scalar logical)
logical indicating whether to bold header rows. Default is TRUE

Value

A {huxtable} object

Excel Output

Use the as_hux_xlsx() function to save a copy of the table in an excel file.

To export a single table, pass a gtsummary object as x; the file is written with a single worksheet. To export multiple tables to one workbook—one table per worksheet—pass a (optionally named) list of gtsummary objects as x. When the list is named, the names are used as the worksheet (tab) names; list elements without a name are assigned a default name of "Sheet {i}".

Author(s)

David Hugh-Jones, Daniel D. Sjoberg

Examples


trial |>
  tbl_summary(by = trt, include = c(age, grade)) |>
  add_p() |>
  as_hux_table()


gtsummary documentation built on Aug. 26, 2026, 9:07 a.m.