Learn R Programming

⚠️There's a newer version (0.9.5) of this package.Take me there.

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.

set_flextable_defaults(
  font.family = "Arial", font.size = 10, 
  border.color = "gray")

flextable(head(cars)) %>% 
  bold(part = "header") %>% 
  add_footer_lines("The 'cars' dataset")

ggplot2::diamonds |> 
  with(table(cut, color)) |> 
  as_flextable()

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.

Installation

install.packages("flextable")

You can get the development version from GitHub:

devtools::install_github("davidgohel/flextable")

Resources

Getting help / questions

If you have questions about how to use the package, visit Stackoverflow and use tags flextable and r Stackoverflow link. You can also use https://github.com/davidgohel/flextable/discussions to start a discussion.

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

74,548

Version

0.9.2

License

GPL-3

Maintainer

David Gohel

Last Published

June 18th, 2023

Functions in flextable (0.9.2)

add_footer_lines

Add labels as new rows in the footer
as_equation

Equation chunk
as_flextable.glm

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

Transform a 'grouped_data' object into a flextable
as_flextable

Method to transform objects into flextables
append_chunks

Append chunks to flextable content
as_b

Bold chunk
as_flextable.pam

Transform a 'pam' object into a flextable
add_header

Add column values as new lines in header
as_bracket

Chunk with values in brackets
as_chunk

Chunk of text wrapper
as_flextable.lm

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

Transform a mixed model into a flextable
as_flextable.tabulator

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

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

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

Transform a 'htest' object into a flextable
as_grouped_data

Add row separators to grouped data
as_highlight

Highlight chunk
autofit

Adjusts cell widths and heights
as_word_field

'Word' computed field
border_outer

Set outer borders
border_inner_v

Set vertical inner borders
as_sub

Subscript chunk
as_sup

Superscript chunk
border_inner_h

Set inner borders
border_inner

Set vertical & horizontal inner borders
colformat_image

Format cells as images
colformat_int

Format integer cells
as_raster

Transform a flextable into a raster
as_paragraph

Concatenate chunks in a flextable
as_flextable.kmeans

Transform a 'kmeans' object into a flextable
as_i

Italic chunk
bold

Set bold font
border

Cell borders update
colformat_char

Format character cells
colformat_double

Format numeric cells
delete_part

Delete flextable part
colformat_datetime

Format datetime cells
as_flextable.data.frame

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

Transform a 'table' object into a flextable
colformat_date

Format date cells
as_flextable.gam

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

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

Set background color
before

Is an element before a match with entries
as_image

Image chunk wrapper
color

Set font color
colorize

Colorize chunk
dim_pretty

Calculate pretty dimensions
fmt_avg_dev

Format content for mean and sd
empty_blanks

Make blank columns as transparent
fmt_2stats

Format content for data generated with summarizor()
flextable_to_rmd

flextable raw code
body_add_flextable

Add flextable into a Word document
fmt_dbl

Format numerical data as percentages
border_remove

Remove borders
chunk_dataframe

Create a chunk representation suitable for flextable
body_replace_flextable_at_bkm

Add flextable at boorkmark location in a Word document
colformat_lgl

Format logical cells
fmt_n_percent

Format content for count data
fmt_pct

Format numerical data as percentages
colformat_num

Format numeric cells
dim.flextable

Get widths and heights of flextable
gg_chunk

'ggplots' chunk wrapper
df_printer

data.frame automatic printing as a flextable
grid_chunk

'Grid Graphics' chunk wrapper
continuous_summary

Continuous columns summary
compose

Define displayed values and mixed content
fp_text_default

Text formatting properties
fp_border_default

Border formatting properties
dim.flextableGrob

Get optimal width and height of a flextable grob
flextable_dim

Get width and height of a flextable object
footers_flextable_at_bkm

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

Set font size
font

Set font
flextable_html_dependency

htmlDependency for flextable objects
keep_with_next

Set Word 'Keep with next' instructions
footnote

Add footnotes to flextable
lollipop

Mini lollipop chart chunk wrapper
linerange

Mini linerange chunk wrapper
headers_flextable_at_bkm

Add flextable at a bookmark location in document's header
flextable-package

flextable: Functions for Tabular Reporting
height

Set flextable rows height
knit_print.flextable

Render flextable with 'knitr'
highlight

Text highlight color
merge_h_range

Rowwise merge of a range of columns
merge_none

Delete flextable merging informations
fmt_int

Format numerical data as integer
fmt_header_n

Format count data for headers
flextable

flextable creation
prepend_chunks

Prepend chunks to flextable content
gen_grob

Convert a flextable to a grid grob object
print.flextable

flextable printing
hline

Set horizontal borders
labelizor

Change displayed labels
get_flextable_defaults

Get flextable defaults formatting properties
line_spacing

Set text alignment
separate_header

Separate collapsed colnames into multiple rows
save_as_rtf

Save flextable objects in an 'RTF' file
hrule

Set flextable rule for rows heights
fit_to_width

Fit a flextable to a maximum width
htmltools_value

flextable as an 'HTML' object
fix_border_issues

Fix border issues when cell are merged
theme_tron

Apply tron theme
ncol_keys

Number of columns
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
nrow_part

Number of rows of a part
theme_tron_legacy

Apply tron legacy theme
padding

Set paragraph paddings
minibar

Mini barplots chunk wrapper
merge_v

Merge flextable cells vertically
plot.flextableGrob

plot a flextable grob
hline_top

Set top horizontal border
hyperlink_text

Chunk of text with hyperlink
plot_chunk

Mini plots chunk wrapper
hline_bottom

Set bottom horizontal border
paginate

Paginate tables
italic

Set italic font
save_as_image

Save a flextable in an 'png' file
plot.flextable

Plot a flextable
save_as_pptx

Save flextable objects in a 'PowerPoint' file
rotate

Rotate cell text
theme_alafoli

Apply alafoli theme
proc_freq

Frequency table
set_caption

Set Caption
theme_vader

Apply Sith Lord Darth Vader theme
set_flextable_defaults

Modify flextable defaults formatting properties
regulartable

flextable old functions
shift_table

Create a shift table
style

Set flextable style
theme_vanilla

Apply vanilla theme
summarizor

Data summary preparation
rtf_add.flextable

Add a 'flextable' into an RTF document
save_as_docx

Save flextable objects in a 'Word' file
surround

Set borders for a selection of cells
set_table_properties

Global table properties
theme_apa

Apply APA theme
vline_left

Set flextable left vertical borders
vline_right

Set flextable right vertical borders
set_header_labels

Change headers labels
save_as_html

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

Get HTML code as a string
theme_zebra

Apply zebra theme
theme_booktabs

Apply booktabs theme
valign

Set vertical alignment
vline

Set vertical borders
theme_box

Apply box theme
set_header_footer_df

Set flextable's header or footer rows
set_formatter

Set column formatter functions
tabulator

Tabulation of aggregations
tabulator_colnames

Column keys of tabulator objects
use_df_printer

Set data.frame automatic printing as a flextable
use_model_printer

set model automatic printing as a flextable
void

Delete flextable content
width

Set columns width
add_footer

Add column values as new lines in footer
align

Set text alignment
add_latex_dep

Add latex dependencies
add_header_lines

Add labels as new rows in the header
add_header_row

Add header labels
add_body

Add column values as new lines in body
add_body_row

Add body labels
add_footer_row

Add footer labels