Learn R Programming

flextable R package

The flextable package provides a framework for easily create tables for reporting and publications. Tables can be easily 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 make it possible to build any table for publication from a data.frame and provides sugar function as_flextable() to convert several R objects to a flextable, such as an object return from table() or a model.

Tables can be embedded within HTML, PDF, Word and PowerPoint documents from R Markdown documents and within RTF or Microsoft Word or PowerPoint documents with package officer. Tables can also be rendered as R plots or graphic files (png).

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)
set_flextable_defaults(
  font.family = "Arial", font.size = 10, 
  border.color = "gray", big.mark = "")

ft <- flextable(head(mtcars)) |> 
  bold(part = "header") 
ft

ft |> 
  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

75,004

Version

0.9.10

License

GPL-3

Maintainer

David Gohel

Last Published

August 24th, 2025

Functions in flextable (0.9.10)

as_flextable.pam

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

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

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

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

Transform a mixed model into a flextable
as_flextable.lm

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

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

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

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

Transform a 'summarizor' object into a flextable
autofit

Adjusts cell widths and heights
as_image

Image chunk wrapper
as_sup

Superscript chunk
as_i

Italic chunk
as_raster

Transform a flextable into a raster
as_grouped_data

Add row separators to grouped data
as_sub

Subscript chunk
as_highlight

Highlight chunk
as_paragraph

Concatenate chunks in a flextable
as_word_field

'Word' computed field
bold

Set bold font
body_replace_flextable_at_bkm

Add flextable at boorkmark location in a Word document
border_inner_v

Set vertical inner borders
border_inner

Set vertical & horizontal inner borders
border_outer

Set outer borders
border_inner_h

Set inner borders
bg

Set background color
body_add_flextable

Add flextable into a Word document
border

Cell borders update
before

Is an element before a match with entries
colformat_datetime

Format datetime cells
colformat_int

Format integer cells
colformat_lgl

Format logical cells
colformat_image

Format cells as images
chunk_dataframe

Create a chunk representation suitable for flextable
border_remove

Remove borders
colformat_char

Format character cells
colformat_date

Format date cells
colformat_double

Format numeric cells
colformat_num

Format numeric cells
colorize

Colorize chunk
dim.flextable

Get widths and heights of flextable
delete_rows

Delete flextable rows
dim.flextableGrob

Get optimal width and height of a flextable grob
color

Set font color
delete_columns

Delete flextable columns
delete_part

Delete flextable part
compose

Define displayed values and mixed content
continuous_summary

Continuous columns summary
df_printer

data.frame automatic printing as a flextable
flextable_html_dependency

htmlDependency for flextable objects
fit_to_width

Fit a flextable to a maximum width
fmt_2stats

Format content for data generated with summarizor()
flextable_dim

Get width and height of a flextable object
flextable

flextable creation
dim_pretty

Calculate pretty dimensions
empty_blanks

Make blank columns as transparent
fix_border_issues

Fix border issues when cell are merged
flextable-package

flextable: Functions for Tabular Reporting
flextable_to_rmd

Knitr rendering in loops and if statements
fmt_n_percent

Format content for count data
font

Set font
fontsize

Set font size
fmt_signif_after_zeros

Format with significant figures after zeros
fmt_header_n

Format count data for headers
fmt_int

Format numerical data as integer
fmt_pct

Format numerical data as percentages
fmt_avg_dev

Format content for mean and sd
footers_flextable_at_bkm

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

Format numerical data
highlight

Text highlight color
fp_text_default

Text formatting properties
grid_chunk

'Grid Graphics' chunk wrapper
gen_grob

Convert a flextable to a grid grob object
gg_chunk

'ggplots' chunk wrapper
fp_border_default

Border formatting properties
headers_flextable_at_bkm

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

Add footnotes to flextable
height

Set flextable rows height
get_flextable_defaults

Get flextable defaults formatting properties
htmltools_value

flextable as an 'HTML' object
hrule

Set flextable rule for rows heights
italic

Set italic font
information_data_paragraph

paragraph related information of a flextable
hline_top

Set top horizontal border
hyperlink_text

Chunk of text with hyperlink
hline

Set horizontal borders
hline_bottom

Set bottom horizontal border
information_data_cell

table cell related information of a flextable
information_data_chunk

content chunk related information of a flextable
merge_none

Delete flextable merging informations
merge_h

Merge flextable cells horizontally
linerange

Mini linerange chunk wrapper
merge_at

Merge flextable cells into a single one
merge_h_range

Rowwise merge of a range of columns
keep_with_next

Set Word 'Keep with next' instructions
lollipop

Mini lollipop chart chunk wrapper
labelizor

Change displayed labels
line_spacing

Set text alignment
knit_print.flextable

Render flextable with 'knitr'
paginate

Paginate tables
plot.flextable

Plot a flextable
plot.flextableGrob

plot a flextable grob
nrow_part

Number of rows of a part
minibar

Mini barplots chunk wrapper
plot_chunk

Mini plots chunk wrapper
merge_v

Merge flextable cells vertically
ph_with.flextable

Add a flextable into a PowerPoint slide
ncol_keys

Number of columns
padding

Set paragraph paddings
save_as_docx

Save flextable objects in a 'Word' file
prepend_chunks

Prepend chunks to flextable content
proc_freq

Frequency table
rtf_add.flextable

Add a 'flextable' into an RTF document
rotate

Rotate cell text
save_as_pptx

Save flextable objects in a 'PowerPoint' file
save_as_html

Save flextable objects in an 'HTML' file
print.flextable

flextable printing
save_as_image

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

flextable old functions
set_formatter_type

Set Formatter by Types of Columns
save_as_rtf

Save flextable objects in an 'RTF' file
set_formatter

Set column formatter functions
set_flextable_defaults

Modify flextable defaults formatting properties
set_header_labels

Change headers labels
set_table_properties

Global table properties
shift_table

Create a shift table
set_caption

Set Caption
set_header_footer_df

Set flextable's header or footer rows
separate_header

Split column names using a separator into multiple rows
theme_apa

Apply APA theme
tab_settings

Set tabulation marks configuration
theme_box

Apply box theme
summarizor

Data summary preparation
surround

Set borders for a selection of cells
tabulator

Tabulation of aggregations
style

Set flextable style
tabulator_colnames

Column keys of tabulator objects
theme_alafoli

Apply alafoli theme
theme_booktabs

Apply booktabs theme
theme_vader

Apply Sith Lord Darth Vader theme
use_model_printer

set model automatic printing as a flextable
to_html.flextable

Get HTML code as a string
theme_tron_legacy

Apply tron legacy theme
use_df_printer

Set data.frame automatic printing as a flextable
theme_vanilla

Apply vanilla theme
theme_zebra

Apply zebra theme
theme_tron

Apply tron theme
vline

Set vertical borders
valign

Set vertical alignment
width

Set columns width
vline_left

Set flextable left vertical borders
void

Delete flextable content
vline_right

Set flextable right vertical borders
add_body_row

Add body labels
add_header_lines

Add labels as new rows in the header
add_header

Add column values as new lines in header
add_footer_row

Add footer labels
add_latex_dep

Add latex dependencies
align

Set text alignment
add_body

Add column values as new lines in body
add_footer_lines

Add labels as new rows in the footer
add_footer

Add column values as new lines in footer
add_header_row

Add header labels
as_bracket

Chunk with values in brackets
as_flextable.gam

Transform a 'gam' model into a flextable
append_chunks

Append chunks to flextable content
as_flextable.glm

Transform a 'glm' 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.grouped_data

Transform a 'grouped_data' object into a flextable
as_equation

Equation chunk
as_chunk

Chunk of text wrapper
as_b

Bold chunk
as_flextable

Method to transform objects into flextables