Learn R Programming

flextable R package

The flextable package provides a framework for easily creating tables for reporting and publications. Tables can be formatted with a set of verbs such as bold(), color(), they can receive a header of more than one line, cells can be merged or contain an image. The package makes it possible to build any table for publication from a data.frame and provides convenience function as_flextable() to convert several R objects to a flextable, such as an object returned from table() or a model.

Tables can be embedded within HTML, PDF, Word and PowerPoint documents from R Markdown and Quarto documents and within RTF or Microsoft Word or PowerPoint documents with package officer. Tables can also be exported as image files (png, svg) or combined with ggplot2 plots in patchwork layouts.

flextable(mtcars) |>
  theme_vanilla() |>
  save_as_docx(path = "mytable.docx")

A flextable object is a data.frame representation. An API is available to let R users create tables for reporting and control their formatting properties and their layout. The package provides functions that give control over:

  • header, body and footer content
  • text, paragraphs, cells and border formatting of any element
  • displayed values

The package also offers a set of high-level functions that allow tabular reporting of statistical models and the creation of complex cross tabulations.

Examples

library(flextable)

flextable(head(airquality))

Formatting can be layered on with a set of functions:

flextable(head(mtcars)) |>
  highlight(i = ~ mpg < 22, j = "disp", color = "#ffe842") |>
  bg(
    j = c("hp", "drat", "wt"),
    bg = scales::col_quantile(palette = c("wheat", "red"), domain = NULL)
  ) |>
  add_footer_lines("The 'mtcars' dataset")
ggplot2::diamonds[, c("cut", "carat", "price", "clarity", "table")] |>
  summarizor(by = c("cut")) |>
  as_flextable(spread_first_col = TRUE)

Installation

install.packages("flextable")

You can get the development version from GitHub:

devtools::install_github("davidgohel/flextable")

Resources

Bug reports

When you file a bug report, please spend some time making it easy for us to reproduce. If you take the time to make the bug report consistent, it will be easier to fix.

Copy Link

Version

Install

install.packages('flextable')

Monthly Downloads

78,877

Version

0.9.11

License

GPL-3

Maintainer

David Gohel

Last Published

February 13th, 2026

Functions in flextable (0.9.11)

as_flextable.gam

Transform a 'gam' model into a flextable
args_x_part_no_all

internal utils for roxygen tags reuse
args_x_part

internal utils for roxygen tags reuse
as_flextable.pam

Transform a 'pam' object into a flextable
as_flextable.summarizor

Transform a 'summarizor' object into a flextable
as_chunk

Text chunk
as_equation

Equation chunk
as_flextable.htest

Transform a 'htest' object into a flextable
as_flextable.lm

Transform a 'lm' object into a flextable
as_flextable.merMod

Transform a 'merMod' or 'lme' object into a flextable
as_flextable.grouped_data

Transform a 'grouped_data' object into a flextable
as_flextable.glm

Transform a 'glm' object into a flextable
as_qmd

Quarto inline markdown chunk
as_highlight

Highlight chunk
as_paragraph

Build a paragraph from chunks
as_grouped_data

Insert group-label rows into a data frame
as_b

Bold chunk
as_image

Image chunk
as_bracket

Bracket chunk
as_flextable.table

Transform a 'table' object into a flextable
as_i

Italic chunk
as_flextable.tabular

Transform a 'tables::tabular' object into a flextable
args_x_j_part

internal utils for roxygen tags reuse
as_flextable

Method to transform objects into flextables
as_flextable.compact_summary

Transform a 'compact_summary' object into a flextable
as_raster

Transform a flextable into a raster
args_x_j

internal utils for roxygen tags reuse
as_flextable.tabulator

Transform a 'tabulator' object into a flextable
as_flextable.kmeans

Transform a 'kmeans' object into a flextable
as_flextable.xtable

Transform a 'xtable' object into a flextable
as_word_field

Word dynamic field chunk
autofit

Adjust cell widths and heights
bold

Set bold font
as_strike

Strikethrough chunk
border

Set cell borders
as_sub

Subscript chunk
body_add_flextable

Add flextable into a Word document
before

Detect rows before a given value
bg

Set background color
as_sup

Superscript chunk
body_replace_flextable_at_bkm

Add flextable at bookmark location in a Word document
colformat_char

Format character cells
colformat_date

Format date cells
colformat_datetime

Format datetime cells
colformat_double

Format double cells
chunk_dataframe

Create a chunk representation suitable for flextable
border_remove

Remove borders
colorize

Colorize chunk
colformat_num

Format numeric cells with format()
border_inner_h

Set inner horizontal borders
color

Set font color
compact_summary

Compact Summary of a Dataset
colformat_lgl

Format logical cells
border_inner

Set all inner borders
border_inner_v

Set inner vertical borders
delete_columns

Delete flextable columns
border_outer

Set outer borders
continuous_summary

Summarize continuous variables as a flextable
colformat_int

Format integer cells
colformat_image

Format cells as images
fix_border_issues

Fix border issues when cells are merged
dim.flextableGrob

Get optimal width and height of a flextable grob
dim_pretty

Calculate optimal column widths and row heights
compose

Set cell content from paragraph chunks
flextable-package

flextable: Functions for Tabular Reporting
empty_blanks

Make blank columns transparent
df_printer

data.frame automatic printing as a flextable
dim.flextable

Get column widths and row heights of a flextable
fmt_avg_dev

Format mean and standard deviation as text
fmt_dbl

Format numbers as doubles
flextable

Create a flextable from a data frame
fit_to_width

Fit a flextable to a maximum width
fmt_header_n

Format count as '(N=XX)' for column headers
fmt_int

Format numbers as integers
flextable_dim

Get overall width and height of a flextable
fp_text_default

Create text formatting with flextable defaults
gen_grob

Render a flextable as a graphic object
fmt_signif_after_zeros

Format with significant figures after zeros
footnote

Add footnotes to flextable
fp_border_default

Create border formatting with flextable defaults
font

Set font
fontsize

Set font size
footers_flextable_at_bkm

Add flextable at a bookmark location in document's footer
flextable_to_rmd

Print a flextable inside knitr loops and conditionals
fmt_2stats

Format summarizor statistics as text
delete_rows

Delete flextable rows
fmt_n_percent

Format count and percentage as text
flextable_selectors

Selectors in flextable
fmt_pct

Format numbers as percentages
delete_part

Delete flextable part
hline_top

Set the top border of a table part
hline_bottom

Set the bottom border of a table part
hrule

Set how row heights are determined
hline

Set horizontal borders below selected rows
grid_chunk

Grid Graphics chunk
flextable_html_dependency

htmlDependency for flextable objects
headers_flextable_at_bkm

Add flextable at a bookmark location in document's header
height

Set flextable rows height
highlight

Set text highlight color
get_flextable_defaults

Get flextable defaults formatting properties
gg_chunk

ggplot chunk
labelizor

Replace displayed text with labels
keep_with_next

Set Word 'Keep with next' instructions
knit_print.flextable

Render flextable in knitr documents
line_spacing

Set line spacing
htmltools_value

Convert a flextable to an HTML object
hyperlink_text

Hyperlink chunk
nrow_part

Number of rows of a part
ncol_keys

Number of columns
minibar

Mini barplot chunk
merge_v

Merge flextable cells vertically
merge_h_range

Rowwise merge of a range of columns
italic

Set italic font
information_data_paragraph

Get paragraph-level information from a flextable
merge_none

Delete flextable merging information
merge_at

Merge flextable cells into a single one
ph_with.flextable

Add a flextable into a PowerPoint slide
merge_h

Merge flextable cells horizontally
padding

Set paragraph paddings
print.flextable

Print a flextable
prepend_chunks

Prepend chunks to flextable content
paginate

Prevent page breaks inside a flextable
linerange

Mini linerange chunk
lollipop

Mini lollipop chart chunk wrapper
plot.flextable

Plot a flextable
proc_freq

Frequency table
plot.flextableGrob

plot a flextable grob
plot_chunk

Mini plot chunk
information_data_cell

Get cell-level information from a flextable
regulartable

flextable old functions
information_data_chunk

Get chunk-level content information from a flextable
set_caption

Set flextable caption
rotate

Rotate cell text
rtf_add.flextable

Add a 'flextable' into an RTF document
separate_header

Split column names using a separator into multiple rows
save_as_rtf

Save flextable objects in an 'RTF' file
save_as_image

Save a flextable in a 'png' or 'svg' file
save_as_pptx

Save flextable objects in a 'PowerPoint' file
save_as_docx

Save flextable objects in a 'Word' file
save_as_html

Save flextable objects in an 'HTML' file
style

Set formatting properties on a flextable selection
summarizor

Prepare descriptive statistics for flextable
surround

Surround cells with borders
tab_settings

Set tabulation marks configuration
set_formatter

Set column formatter functions
set_formatter_type

Set Formatter by Types of Columns
tabulator

Create pivot-style summary tables
theme_alafoli

Apply alafoli theme
set_header_footer_df

Replace the entire header or footer from a data frame
set_header_labels

Rename column labels in the header
tabulator_colnames

Column keys of tabulator objects
theme_tron_legacy

Apply tron legacy theme
set_flextable_defaults

Modify flextable defaults formatting properties
theme_borderless

Apply borderless theme
theme_booktabs

Apply booktabs theme
shift_table

Create a shift table
set_table_properties

Set table layout and width properties
to_html.flextable

Get HTML code as a string
theme_tron

Apply tron theme
theme_box

Apply box theme
use_flextable_qmd

Install the flextable-qmd Quarto extension
use_model_printer

Set automatic flextable printing for models
theme_vanilla

Apply vanilla theme
theme_zebra

Apply zebra theme
theme_vader

Apply Sith Lord Darth Vader theme
valign

Set vertical alignment
theme_apa

Apply APA theme
vline_right

Set the right border of the table
wrap_flextable

Wrap a flextable for use with patchwork
vline_left

Set the left border of the table
use_df_printer

Set data.frame automatic printing as a flextable
width

Set columns width
void

Clear the displayed content of selected columns
vline

Set vertical borders to the right of selected columns
add_header

Add header rows with one value per column
add_footer_lines

Add full-width rows to the footer
align

Set text alignment
add_footer_row

Add a footer row with spanning labels
add_latex_dep

Add latex dependencies
add_footer

Add footer rows with one value per column
add_header_lines

Add full-width rows to the header
add_body_row

Add a body row with spanning labels
add_body

Add body rows with one value per column
add_header_row

Add a header row with spanning labels
args_x_j_part_no_all

internal utils for roxygen tags reuse
args_selectors_without_all

internal utils for roxygen tags reuse
args_x_i_j

internal utils for roxygen tags reuse
args_x_only

internal utils for roxygen tags reuse
args_x_i_part_no_all

internal utils for roxygen tags reuse
args_x_i_part

internal utils for roxygen tags reuse
as_flextable.data.frame

Transform and summarise a 'data.frame' into a flextable Simple summary of a data.frame as a flextable
args_selectors_with_all

internal utils for roxygen tags reuse
append_chunks

Append chunks to flextable content