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

84,343

Version

0.10.1

License

GPL-3

Maintainer

David Gohel

Last Published

September 10th, 2026

Functions in flextable (0.10.1)

as_chunk

Text chunk
as_flextable.compact_summary

Transform a 'compact_summary' object into a flextable
as_flextable

Method to transform objects into flextables
as_equation

Equation chunk
as_flextable.TableTree

Transform an rtables object 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.merMod

Transform a 'merMod' or 'lme' 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
as_flextable.pam

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

Transform a 'gam' model into a flextable
as_b

Bold chunk
as_bracket

Bracket chunk
as_flextable.lm

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

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

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

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

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

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

Transform a 'grouped_data' object into a flextable
as_image

Image chunk
as_grouped_data

Insert group-label rows into a data frame
as_i

Italic chunk
as_paragraph

Build a paragraph from chunks
as_flextable.xtable

Transform a 'xtable' object into a flextable
as_raster

Transform a flextable into a raster
as_highlight

Highlight chunk
as_flextable.tabular

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

Quarto inline markdown chunk
as_flextable.tabulator

Transform a 'tabulator' object into a flextable
bold

Set bold font
body_add_flextable

Add flextable into a Word document
as_sub

Subscript chunk
autofit

Adjust columns to their content size
as_strike

Strikethrough chunk
as_sup

Superscript chunk
as_word_field

Word dynamic field chunk
before

Detect rows before a given value
bg

Set background color
body_replace_flextable_at_bkm

Add flextable at bookmark location in a Word document
border_remove

Remove borders
chunk_dataframe

Create a chunk representation suitable for flextable
colformat_char

Format character cells
border_inner_h

Set inner horizontal borders
border_inner_v

Set inner vertical borders
colformat_datetime

Format datetime cells
border_outer

Set outer borders
border_inner

Set all inner borders
colformat_date

Format date cells
border

Set cell borders
colformat_int

Format integer cells
colorize

Colorize chunk
compose

Set cell content from paragraph chunks
colformat_image

Format cells as images
colformat_lgl

Format logical cells
colformat_num

Format numeric cells with format()
colformat_double

Format double cells
continuous_summary

Summarize continuous variables as a flextable
compact_summary

Compact Summary of a Dataset
color

Set font color
dim.flextableGrob

Get optimal width and height of a flextable grob
fit_columns

Constrain table width by wrapping text
delete_rows

Delete flextable rows
delete_part

Delete flextable part
dim_pretty

Calculate optimal column widths and row heights
delete_columns

Delete flextable columns
df_printer

data.frame automatic printing as a flextable
dim.flextable

Get column widths and row heights of a flextable
empty_blanks

Make blank columns transparent
fit_to_width

Constrain table width by shrinking font size
flextable-package

flextable: Functions for Tabular Reporting
fmt_avg_dev

Format mean and standard deviation as text
flextable_selectors

Selectors in flextable
flextable_to_rmd

Print a flextable inside knitr loops and conditionals
fmt_dbl

Format numbers as doubles
fmt_2stats

Format summarizor statistics as text
flextable_dim

Get overall width and height of a flextable
flextable

Create a flextable from a data frame
flextable_html_dependency

htmlDependency for flextable objects
fix_border_issues

Fix border issues when cells are merged
fmt_n_percent

Format count and percentage as text
fontsize

Set font size
fp_border_default

Create border formatting with flextable defaults
footnote

Add footnotes to flextable
footers_flextable_at_bkm

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

Format numbers as percentages
font

Set font
fmt_int

Format numbers as integers
fmt_signif_after_zeros

Format with significant figures after zeros
fmt_header_n

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

Get flextable defaults formatting properties
hline_bottom

Set the bottom border of a table part
hline

Set horizontal borders below selected rows
highlight

Set text highlight color
fp_text_default

Create text formatting with flextable defaults
height

Set flextable rows height
grid_chunk

Grid Graphics chunk
gg_chunk

ggplot chunk
headers_flextable_at_bkm

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

Render a flextable as a graphic object
indentation

Set paragraph indents
htmltools_value

Convert a flextable to an HTML object
hyperlink_text

Hyperlink chunk
hline_top

Set the top border of a table part
information_data_cell

Get cell-level information from a flextable
hrule

Set how row heights are determined
italic

Set italic font
keep_with_next

Set Word 'Keep with next' instructions
information_data_paragraph

Get paragraph-level information from a flextable
information_data_chunk

Get chunk-level content information from a flextable
line_spacing

Set line spacing
linerange

Mini linerange chunk
merge_at

Merge flextable cells into a single one
lollipop

Mini lollipop chart chunk wrapper
knit_print.flextable

Render flextable in knitr documents
labelizor

Replace displayed text with labels
merge_h_range

Rowwise merge of a range of columns
merge_h

Merge flextable cells horizontally
plot.flextableGrob

plot a flextable grob
plot_chunk

Mini plot chunk
minibar

Mini barplot chunk
nrow_part

Number of rows of a part
ncol_keys

Number of columns
paginate

Prevent page breaks inside a flextable
padding

Set paragraph paddings
rotate

Rotate cell text
repair_docx

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

Delete flextable merging information
merge_v

Merge flextable cells vertically
rtf_add.flextable

Add a 'flextable' into an RTF document
save_as_docx

Save flextable objects in a 'Word' file
note_docx_images

internal utils for roxygen tags reuse
plot.flextable

Plot a flextable
save_as_html

Save flextable objects in an 'HTML' file
save_as_rtf

Save flextable objects in an 'RTF' file
save_as_pptx

Save flextable objects in a 'PowerPoint' file
ph_with.flextable

Add a flextable into a PowerPoint slide
set_formatter

Set column formatter functions
proc_freq

Frequency table
save_as_image

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

Replace the entire header or footer from a data frame
set_formatter_type

Set Formatter by Types of Columns
prepend_chunks

Prepend chunks to flextable content
set_header_labels

Rename column labels in the header
print.flextable

Print a flextable
set_caption

Set flextable caption
set_flextable_defaults

Modify flextable defaults formatting properties
style

Set formatting properties on a flextable selection
split_to_pages

Split a flextable into pages by rows and columns
split_rows

Split a flextable into pages by rows
tab_settings

Set tabulation marks configuration
separate_header

Split column names using a separator into multiple rows
regulartable

flextable old functions
shift_table

Create a shift table
split_columns

Split a flextable into pages by columns
save_as_typst

Save flextable objects in a Typst file
tabulator

Create pivot-style summary tables
set_table_properties

Set table layout and width properties
surround

Surround cells with borders
summarizor

Prepare descriptive statistics for flextable
theme_vader

Apply Sith Lord Darth Vader theme
theme_apa

Apply APA theme
theme_booktabs

Apply booktabs theme
tabulator_colnames

Column keys of tabulator objects
theme_tron

Apply tron theme
theme_alafoli

Apply alafoli theme
theme_vanilla

Apply vanilla theme
theme_tron_legacy

Apply tron legacy theme
theme_box

Apply box theme
theme_borderless

Apply borderless theme
theme_zebra

Apply zebra theme
to_html.flextable

Get HTML code as a string
use_df_printer

Set data.frame automatic printing as a flextable
valign

Set vertical alignment
use_flextable_qmd

Install the flextable-qmd Quarto extension
vline_right

Set the right border of the table
void

Clear the displayed content of selected columns
vline

Set vertical borders to the right of selected columns
use_model_printer

Set automatic flextable printing for models
vline_left

Set the left border of the table
wrap_flextable

Wrap a flextable for use with patchwork
width

Set columns width
add_footer_row

Add a footer row with spanning labels
add_body_row

Add a body row with spanning labels
add_header_lines

Add full-width rows to the header
add_header

Add header rows with one value per column
add_body

Add body rows with one value per column
add_footer

Add footer rows with one value per column
add_footer_lines

Add full-width rows to the footer
add_header_row

Add a header row with spanning labels
add_latex_dep

Add latex dependencies
align

Set text alignment
args_x_i_part

internal utils for roxygen tags reuse
append_chunks

Append chunks to flextable content
args_selectors_without_all

internal utils for roxygen tags reuse
args_x_i_part_no_all

internal utils for roxygen tags reuse
args_x_only

internal utils for roxygen tags reuse
args_x_j

internal utils for roxygen tags reuse
args_x_i_j

internal utils for roxygen tags reuse
args_x_j_part_no_all

internal utils for roxygen tags reuse
args_x_j_part

internal utils for roxygen tags reuse
args_selectors_with_all

internal utils for roxygen tags reuse