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

100,845

Version

0.10.4

License

GPL-3

Maintainer

David Gohel

Last Published

November 8th, 2026

Functions in flextable (0.10.4)

as_flextable.merMod

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

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

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

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

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

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

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

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

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

Transform a 'summarizor' object into a flextable
as_strike

Strikethrough chunk
as_highlight

Highlight chunk
as_raster

Transform a flextable into a raster
as_image

Image chunk
as_paragraph

Build a paragraph from chunks
as_grouped_data

Insert group-label rows into a data frame
as_qmd

Quarto inline markdown chunk
as_flextable.xtable

Transform a 'xtable' object into a flextable
as_i

Italic chunk
as_flextable.tabulator

Transform a 'tabulator' object into a flextable
body_add_flextable

Add flextable into a Word document
as_sup

Superscript chunk
autofit

Adjust columns to their content size
as_word_field

Word dynamic field chunk
before

Detect rows before a given value
body_replace_flextable_at_bkm

Add flextable at bookmark location in a Word document
bold

Set bold font
as_sub

Subscript chunk
bg

Set background color
border

Set cell borders
border_inner_v

Set inner vertical borders
border_remove

Remove borders
colformat_double

Format double cells
border_inner_h

Set inner horizontal borders
colformat_datetime

Format datetime cells
border_inner

Set all inner borders
chunk_dataframe

Create a chunk representation suitable for flextable
colformat_date

Format date cells
colformat_char

Format character cells
border_outer

Set outer borders
compact_summary

Compact Summary of a Dataset
colorize

Colorize chunk
delete_columns

Delete flextable columns
continuous_summary

Summarize continuous variables as a flextable
colformat_num

Format numeric cells with format()
colformat_image

Format cells as images
color

Set font color
compose

Set cell content from paragraph chunks
colformat_int

Format integer cells
colformat_lgl

Format logical cells
dim_pretty

Calculate optimal column widths and row heights
dim.flextable

Get column widths and row heights of a flextable
fix_border_issues

Fix border issues when cells are merged
fit_to_width

Constrain table width by shrinking font size
empty_blanks

Make blank columns transparent
dim.flextableGrob

Get optimal width and height of a flextable grob
df_printer

data.frame automatic printing as a flextable
delete_part

Delete flextable part
fit_columns

Constrain table width by wrapping text
delete_rows

Delete flextable rows
fmt_header_n

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

Get overall width and height of a flextable
flextable_html_dependency

htmlDependency for flextable objects
flextable

Create a flextable from a data frame
fmt_avg_dev

Format mean and standard deviation as text
fmt_2stats

Format summarizor statistics as text
flextable_to_rmd

Print a flextable inside knitr loops and conditionals
flextable-package

flextable: Functions for Tabular Reporting
fmt_dbl

Format numbers as doubles
flextable_selectors

Selectors in flextable
fp_text_default

Create text formatting with flextable defaults
fontsize

Set font size
fp_border_default

Create border formatting with flextable defaults
fmt_n_percent

Format count and percentage as text
font

Set font
fmt_int

Format numbers as integers
footers_flextable_at_bkm

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

Format with significant figures after zeros
footnote

Add footnotes to flextable
fmt_pct

Format numbers as percentages
get_flextable_defaults

Get flextable defaults formatting properties
hline_top

Set the top border of a table part
grid_chunk

Grid Graphics chunk
headers_flextable_at_bkm

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

Set the bottom border of a table part
gen_grob

Render a flextable as a graphic object
gg_chunk

ggplot chunk
hline

Set horizontal borders below selected rows
highlight

Set text highlight color
height

Set flextable rows height
information_data_paragraph

Get paragraph-level information from a flextable
hrule

Set how row heights are determined
information_data_cell

Get cell-level information from a flextable
indentation

Set paragraph indents
hyperlink_text

Hyperlink chunk
italic

Set italic font
htmltools_value

Convert a flextable to an HTML object
keep_with_next

Set Word 'Keep with next' instructions
information_data_chunk

Get chunk-level content information from a flextable
image_raster

Read an image as a native raster, with a cache
linerange

Mini linerange chunk
merge_h

Merge flextable cells horizontally
merge_none

Delete flextable merging information
lollipop

Mini lollipop chart chunk wrapper
merge_at

Merge flextable cells into a single one
line_spacing

Set line spacing
knit_print.flextable

Render flextable in knitr documents
merge_h_range

Rowwise merge of a range of columns
labelizor

Replace displayed text with labels
layout_lines

Arrange pieces of text into lines
nrow_part

Number of rows of a part
plot.flextable

Plot a flextable
merge_v

Merge flextable cells vertically
minibar

Mini barplot chunk
ph_with.flextable

Add a flextable into a PowerPoint slide
padding

Set paragraph paddings
paginate

Prevent page breaks inside a flextable
note_docx_images

internal utils for roxygen tags reuse
ncol_keys

Number of columns
plot.flextableGrob

plot a flextable grob
repair_docx

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

Save flextable objects in a 'Word' file
print.flextable

Print a flextable
proc_freq

Frequency table
save_as_html

Save flextable objects in an 'HTML' file
plot_chunk

Mini plot chunk
rtf_add.flextable

Add a 'flextable' into an RTF document
rotate

Rotate cell text
regulartable

flextable old functions
prepend_chunks

Prepend chunks to flextable content
save_as_image

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

Split column names using a separator into multiple rows
save_as_rtf

Save flextable objects in an 'RTF' file
set_caption

Set flextable caption
save_as_typst

Save flextable objects in a Typst file
set_header_footer_df

Replace the entire header or footer from a data frame
save_as_pptx

Save flextable objects in a 'PowerPoint' file
set_formatter

Set column formatter functions
set_formatter_type

Set Formatter by Types of Columns
set_flextable_defaults

Modify flextable defaults formatting properties
set_header_labels

Rename column labels in the header
tab_settings

Set tabulation marks configuration
summarizor

Prepare descriptive statistics for flextable
style

Set formatting properties on a flextable selection
split_to_pages

Split a flextable into pages by rows and columns
set_table_properties

Set table layout and width properties
shift_table

Create a shift table
surround

Surround cells with borders
split_columns

Split a flextable into pages by columns
split_rows

Split a flextable into pages by rows
theme_tron_legacy

Apply tron legacy theme
theme_alafoli

Apply alafoli theme
theme_tron

Apply tron theme
theme_apa

Apply APA theme
theme_vader

Apply Sith Lord Darth Vader theme
theme_borderless

Apply borderless theme
tabulator

Create pivot-style summary tables
theme_box

Apply box theme
theme_booktabs

Apply booktabs theme
tabulator_colnames

Column keys of tabulator objects
theme_vanilla

Apply vanilla theme
vline_right

Set the right border of the table
use_model_printer

Set automatic flextable printing for models
valign

Set vertical alignment
use_df_printer

Set data.frame automatic printing as a flextable
to_html.flextable

Get HTML code as a string
theme_zebra

Apply zebra theme
vline_left

Set the left border of the table
vline

Set vertical borders to the right of selected columns
use_flextable_qmd

Install the flextable-qmd Quarto extension
void

Clear the displayed content of selected columns
width

Set columns width
wrap_flextable

Wrap a flextable for use with patchwork
add_footer_lines

Add full-width rows to the footer
add_header_lines

Add full-width rows to the header
align

Set text alignment
add_latex_dep

Add latex dependencies
add_footer_row

Add a footer row with spanning labels
add_footer

Add footer rows with one value per column
add_header

Add header rows with one value per column
add_header_row

Add a header row with spanning labels
add_body_row

Add a body row with spanning labels
add_body

Add body rows with one value per column
as_equation

Equation chunk
as_b

Bold chunk
append_chunks

Append chunks to flextable content
as_chunk

Text chunk
as_flextable

Method to transform objects into flextables
as_flextable.TableTree

Transform an rtables object into a flextable
as_flextable.compact_summary

Transform a 'compact_summary' object into a flextable
as_flextable.gam

Transform a 'gam' model 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
as_bracket

Bracket chunk