Every flextable is divided into three parts: header, body, and footer. Most formatting functions accept aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/davidgohel/flextable/llms.txt
Use this file to discover all available pages before exploring further.
part argument that controls which part they act on.
Creating a flextable
Pass anydata.frame to flextable() to create a table:
data— adata.frame(tibbles and data.tables are coerced automatically).col_keys— the columns to display, in display order. Defaults to all column names.cwidth,cheight— initial cell width and height in inches.use_labels— ifTRUE, column labels from labelled data will be used in the header.
The three parts
Header
The header is created automatically from the column names (or The header always has exactly one row after construction. Additional header rows can be added with
col_keys). Each column name becomes a single header cell. If use_labels = TRUE and the dataset carries variable labels, those labels replace the raw column names.add_header_row().Body
The body contains the data rows from the supplied Formatting functions target the body by default (
data.frame. The number of body rows equals nrow(data).part = "body").The col_keys parameter and blank columns
col_keys controls which columns appear and in what order. If a name in col_keys does not exist in the data, flextable adds it as a blank column — useful for inserting spacing columns or gaps between groups.
col_keys that are not in the data are created as empty character columns. They appear blank in all output formats. You can use them as visual separators.
Duplicate values in
col_keys are not allowed and will raise an error.The part argument
Formatting functions like bold(), color(), bg(), and align() all accept a part argument:
| Value | Targets |
|---|---|
"body" | Data rows (default) |
"header" | Header rows |
"footer" | Footer rows |
"all" | All three parts |
part = "all", the operation is applied to each part independently. Formula row selectors (i = ~ condition) cannot be used with part = "all" or with "header" / "footer", because those parts store only character values — see Selectors for details.
Inspecting a flextable
Use these functions to query the dimensions of a flextable object:nrow_part() is especially useful when you need to programmatically target the last row:
Quick construction with qflextable()
qflextable() is a shortcut that creates a flextable, sets fixed table layout, and calls autofit() in one step:
qflextable() when you want a quick, well-sized table without further customization.
Pipe-friendly API
All flextable functions accept a flextable object as their first argument and return a modified flextable object. This makes them composable with the native pipe (|>) or magrittr pipe (%>%):
Internal object structure
A flextable is an R list of class"flextable". Its top-level elements are:
| Element | Description |
|---|---|
$header | A complex_tabpart with header rows, styles, and content |
$body | A complex_tabpart with body rows, styles, and content |
$footer | A complex_tabpart with footer rows, styles, and content |
$col_keys | Character vector of displayed column names in order |
$blanks | Names of blank columns added from col_keys |
$caption | Caption settings set by set_caption() |