| formatTable | R Documentation |
Creates a flextable object from a dataframe using a delimiter to span the header, and allows to easily customise table style.
formatTable(
x,
type = NULL,
delim = "\n",
style = NULL,
na = "–",
title = NULL,
subtitle = NULL,
caption = NULL,
groupColumn = NULL,
groupAsColumn = FALSE,
groupOrder = NULL,
merge = "all_columns"
)
x |
A dataframe. |
type |
Character string specifying the desired output table format.
See |
delim |
Delimiter to separate headers. |
style |
Defines the visual formatting of the table. This argument can be provided in one of the following ways:
|
na |
How to display missing values. Not used for "datatable" and "reactable". |
title |
Title of the table, or NULL for no title. Not used for "datatable". |
subtitle |
Subtitle of the table, or NULL for no subtitle. Not used for "datatable" and "reactable". |
caption |
Caption for the table, or NULL for no caption. Text in
markdown formatting style (e.g. |
groupColumn |
Columns to use as group labels, to see options use
*tidy: The tidy format applied to column names replaces "_" with a space and
converts to sentence case. Use |
groupAsColumn |
Whether to display the group labels as a column (TRUE) or rows (FALSE). Not used for "datatable" and "reactable" |
groupOrder |
Order in which to display group labels. Not used for "datatable" and "reactable". |
merge |
Names of the columns to merge vertically when consecutive row cells have identical values. Alternatively, use "all_columns" to apply this merging to all columns, or use NULL to indicate no merging. Not used for "datatable" and "reactable". |
A formatted table of the class selected in "type" argument.
# Example 1
mockSummarisedResult() |>
formatEstimateValue(decimals = c(integer = 0, numeric = 1)) |>
formatHeader(
header = c("Study strata", "strata_name", "strata_level"),
includeHeaderName = FALSE
) |>
formatTable(
type = "flextable",
style = "default",
na = "--",
title = "fxTable example",
subtitle = NULL,
caption = NULL,
groupColumn = "group_level",
groupAsColumn = TRUE,
groupOrder = c("cohort1", "cohort2"),
merge = "all_columns"
)
# Example 2
mockSummarisedResult() |>
formatEstimateValue(decimals = c(integer = 0, numeric = 1)) |>
formatHeader(header = c("Study strata", "strata_name", "strata_level"),
includeHeaderName = FALSE) |>
formatTable(
type = "gt",
style = list("header" = list(
gt::cell_fill(color = "#d9d9d9"),
gt::cell_text(weight = "bold")),
"header_level" = list(gt::cell_fill(color = "#e1e1e1"),
gt::cell_text(weight = "bold")),
"column_name" = list(gt::cell_text(weight = "bold")),
"title" = list(gt::cell_text(weight = "bold"),
gt::cell_fill(color = "#c8c8c8")),
"group_label" = gt::cell_fill(color = "#e1e1e1")),
na = "--",
title = "gtTable example",
subtitle = NULL,
caption = NULL,
groupColumn = "group_level",
groupAsColumn = FALSE,
groupOrder = c("cohort1", "cohort2"),
merge = "all_columns"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.