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 (plus Typst with Quarto) 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

109,598

Version

0.10.0

License

GPL-3

Maintainer

David Gohel

Last Published

July 7th, 2026

Functions in flextable (0.10.0)

args_x_j

internal utils for roxygen tags reuse
args_x_j_part

internal utils for roxygen tags reuse
args_x_j_part_no_all

internal utils for roxygen tags reuse
args_x_only

internal utils for roxygen tags reuse
args_x_i_j

internal utils for roxygen tags reuse
args_selectors_without_all

internal utils for roxygen tags reuse
as_flextable.compact_summary

Transform a 'compact_summary' object into a flextable
as_flextable.data.frame

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

Append chunks to flextable content
as_b

Bold chunk
as_bracket

Bracket chunk
args_selectors_with_all

internal utils for roxygen tags reuse
as_flextable.kmeans

Transform a 'kmeans' object into a flextable
as_flextable

Method to transform objects into flextables
as_flextable.TableTree

Transform an rtables object into a flextable
args_x_i_part

internal utils for roxygen tags reuse
args_x_i_part_no_all

internal utils for roxygen tags reuse
as_flextable.grouped_data

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

Transform a 'htest' object into a flextable
as_equation

Equation chunk
as_chunk

Text chunk
as_flextable.table

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

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

Transform a 'lm' object into a flextable
args_x_part_no_all

internal utils for roxygen tags reuse
as_flextable.merMod

Transform a 'merMod' or 'lme' object into a flextable
as_qmd

Quarto inline markdown chunk
args_x_part

internal utils for roxygen tags reuse
as_i

Italic chunk
as_highlight

Highlight chunk
as_flextable.pam

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

Transform a 'xtable' object into a flextable
as_grouped_data

Insert group-label rows into a data frame
as_flextable.tabular

Transform a 'tables::tabular' object into a flextable
as_flextable.gam

Transform a 'gam' model into a flextable
as_flextable.tabulator

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

Transform a 'glm' object into a flextable
as_image

Image chunk
as_paragraph

Build a paragraph from chunks
bold

Set bold font
body_replace_flextable_at_bkm

Add flextable at bookmark location in a Word document
border

Set cell borders
bg

Set background color
body_add_flextable

Add flextable into a Word document
border_remove

Remove borders
border_outer

Set outer borders
as_raster

Transform a flextable into a raster
border_inner

Set all inner borders
colformat_datetime

Format datetime cells
autofit

Adjust columns to their content size
before

Detect rows before a given value
border_inner_h

Set inner horizontal borders
as_word_field

Word dynamic field chunk
as_sup

Superscript chunk
border_inner_v

Set inner vertical borders
as_sub

Subscript chunk
as_strike

Strikethrough chunk
colformat_date

Format date cells
chunk_dataframe

Create a chunk representation suitable for flextable
colorize

Colorize chunk
compose

Set cell content from paragraph chunks
compact_summary

Compact Summary of a Dataset
colformat_char

Format character cells
continuous_summary

Summarize continuous variables as a flextable
colformat_int

Format integer cells
colformat_image

Format cells as images
colformat_double

Format double cells
fit_to_width

Constrain table width by shrinking font size
df_printer

data.frame automatic printing as a flextable
delete_rows

Delete flextable rows
colformat_lgl

Format logical cells
fit_columns

Constrain table width by wrapping text
dim.flextable

Get column widths and row heights of a flextable
color

Set font color
colformat_num

Format numeric cells with format()
dim.flextableGrob

Get optimal width and height of a flextable grob
dim_pretty

Calculate optimal column widths and row heights
empty_blanks

Make blank columns transparent
delete_columns

Delete flextable columns
flextable_to_rmd

Print a flextable inside knitr loops and conditionals
fmt_2stats

Format summarizor statistics as text
delete_part

Delete flextable part
flextable

Create a flextable from a data frame
flextable_selectors

Selectors in flextable
font

Set font
flextable-package

flextable: Functions for Tabular Reporting
flextable_html_dependency

htmlDependency for flextable objects
fix_border_issues

Fix border issues when cells are merged
fmt_signif_after_zeros

Format with significant figures after zeros
fp_border_default

Create border formatting with flextable defaults
flextable_dim

Get overall width and height of a flextable
footnote

Add footnotes to flextable
fontsize

Set font size
footers_flextable_at_bkm

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

Create text formatting with flextable defaults
hline

Set horizontal borders below selected rows
hline_bottom

Set the bottom border of a table part
gen_grob

Render a flextable as a graphic object
headers_flextable_at_bkm

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

Grid Graphics chunk
hline_top

Set the top border of a table part
height

Set flextable rows height
highlight

Set text highlight color
get_flextable_defaults

Get flextable defaults formatting properties
fmt_int

Format numbers as integers
fmt_header_n

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

Get paragraph-level information from a flextable
fmt_pct

Format numbers as percentages
fmt_dbl

Format numbers as doubles
fmt_avg_dev

Format mean and standard deviation as text
fmt_n_percent

Format count and percentage as text
information_data_chunk

Get chunk-level content information from a flextable
keep_with_next

Set Word 'Keep with next' instructions
htmltools_value

Convert a flextable to an HTML object
hyperlink_text

Hyperlink chunk
italic

Set italic font
indentation

Set paragraph indents
information_data_cell

Get cell-level information from a flextable
gg_chunk

ggplot chunk
merge_at

Merge flextable cells into a single one
lollipop

Mini lollipop chart chunk wrapper
linerange

Mini linerange chunk
line_spacing

Set line spacing
knit_print.flextable

Render flextable in knitr documents
merge_h_range

Rowwise merge of a range of columns
ph_with.flextable

Add a flextable into a PowerPoint slide
hrule

Set how row heights are determined
padding

Set paragraph paddings
merge_h

Merge flextable cells horizontally
nrow_part

Number of rows of a part
note_docx_images

internal utils for roxygen tags reuse
ncol_keys

Number of columns
labelizor

Replace displayed text with labels
minibar

Mini barplot chunk
paginate

Prevent page breaks inside a flextable
merge_none

Delete flextable merging information
merge_v

Merge flextable cells vertically
rtf_add.flextable

Add a 'flextable' into an RTF document
save_as_image

Save a flextable in a 'png' or 'svg' file
plot.flextable

Plot a flextable
save_as_docx

Save flextable objects in a 'Word' file
save_as_html

Save flextable objects in an 'HTML' file
proc_freq

Frequency table
regulartable

flextable old functions
plot_chunk

Mini plot chunk
rotate

Rotate cell text
plot.flextableGrob

plot a flextable grob
repair_docx

Repair flextables in a 'Word' document produced by 'pandoc'
prepend_chunks

Prepend chunks to flextable content
print.flextable

Print a flextable
set_header_footer_df

Replace the entire header or footer from a data frame
set_caption

Set flextable caption
set_flextable_defaults

Modify flextable defaults formatting properties
separate_header

Split column names using a separator into multiple rows
save_as_typst

Save flextable objects in a Typst file
save_as_rtf

Save flextable objects in an 'RTF' file
save_as_pptx

Save flextable objects in a 'PowerPoint' file
style

Set formatting properties on a flextable selection
set_formatter

Set column formatter functions
set_formatter_type

Set Formatter by Types of Columns
split_to_pages

Split a flextable into pages by rows and columns
tabulator

Create pivot-style summary tables
set_header_labels

Rename column labels in the header
tab_settings

Set tabulation marks configuration
tabulator_colnames

Column keys of tabulator objects
surround

Surround cells with borders
summarizor

Prepare descriptive statistics for flextable
theme_alafoli

Apply alafoli theme
theme_borderless

Apply borderless theme
theme_vanilla

Apply vanilla theme
set_table_properties

Set table layout and width properties
split_columns

Split a flextable into pages by columns
split_rows

Split a flextable into pages by rows
use_df_printer

Set data.frame automatic printing as a flextable
use_flextable_qmd

Install the flextable-qmd Quarto extension
theme_box

Apply box theme
void

Clear the displayed content of selected columns
theme_vader

Apply Sith Lord Darth Vader theme
shift_table

Create a shift table
vline_right

Set the right border of the table
vline

Set vertical borders to the right of selected columns
theme_tron_legacy

Apply tron legacy theme
theme_tron

Apply tron theme
theme_booktabs

Apply booktabs theme
use_model_printer

Set automatic flextable printing for models
theme_apa

Apply APA theme
valign

Set vertical alignment
width

Set columns width
to_html.flextable

Get HTML code as a string
theme_zebra

Apply zebra theme
vline_left

Set the left border of the table
wrap_flextable

Wrap a flextable for use with patchwork