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.

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

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

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

77,938

Version

0.9.0

License

GPL-3

Maintainer

David Gohel

Last Published

March 14th, 2023

Functions in flextable (0.9.0)

add_footer

Add column values as new lines in footer
add_latex_dep

Add latex dependencies
align

Set text alignment
add_body

Add column values as new lines in body
add_header_row

Add header labels
add_header_lines

Add labels as new rows in the header
add_body_row

Add body labels
as_flextable.data.frame

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

Chunk with values in brackets
add_footer_lines

Add labels as new rows in the footer
as_flextable.glm

Transform a 'glm' object into a flextable
add_footer_row

Add footer labels
as_flextable.gam

Transform a 'gam' model into a flextable
as_image

Image chunk wrapper
as_flextable.grouped_data

Transform a 'grouped_data' object into a flextable
add_header

Add column values as new lines in header
as_chunk

Chunk of text wrapper
as_equation

Equation chunk
as_grouped_data

Add row separators to grouped data
as_flextable.xtable

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

Transform a 'htest' object into a flextable
append_chunks

Append chunks to flextable content
as_flextable

Method to transform objects into flextables
border_inner_v

Set vertical inner borders
as_paragraph

Concatenate chunks in a flextable
as_flextable.tabular

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

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

Transform a 'kmeans' object into a flextable
as_highlight

Highlight chunk
border_outer

Set outer borders
as_flextable.tabulator

Transform a 'tabulator' object into a flextable
as_i

Italic chunk
colformat_int

Format integer cells
colformat_image

Format cells as images
border_inner

Set vertical & horizontal inner borders
as_flextable.merMod

Transform a mixed model into a flextable
fit_to_width

Fit a flextable to a maximum width
border_inner_h

Set inner borders
colformat_char

Format character cells
bold

Set bold font
autofit

Adjusts cell widths and heights
colformat_date

Format date cells
as_b

Bold chunk
as_flextable.summarizor

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

Transform a 'pam' object into a flextable
as_raster

Transform a flextable into a raster
as_sup

Superscript chunk
fix_border_issues

Fix border issues when cell are merged
fmt_n_percent

Format content for count data
border

Cell borders update
colformat_lgl

Format logical cells
colformat_num

Format numeric cells
delete_part

Delete flextable part
empty_blanks

Make blank columns as transparent
dim_pretty

Calculate pretty dimensions
before

Is an element before a match with entries
df_printer

data.frame automatic printing as a flextable
colformat_double

Format numeric cells
colformat_datetime

Format datetime cells
as_word_field

'Word' computed field
as_sub

Subscript chunk
bg

Set background color
flextable-package

flextable: Functions for Tabular Reporting
body_add_flextable

Add flextable into a Word document
font

Set font
get_flextable_defaults

Get flextable defaults formatting properties
gg_chunk

'ggplots' chunk wrapper
grid_chunk

'Grid Graphics' chunk wrapper
flextable

flextable creation
flextable_to_rmd

flextable raw code
hline

Set horizontal borders
headers_flextable_at_bkm

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

Format content for data generated with summarizor()
border_remove

Remove borders
gen_grob

Convert a flextable to a grid grob object
fp_text_default

Text formatting properties
dim.flextable

Get widths and heights of flextable
dim.flextableGrob

Get optimal width and height of a flextable grob
merge_h_range

Rowwise merge of a range of columns
hline_bottom

Set bottom horizontal border
htmltools_value

flextable as an 'HTML' object
height

Set flextable rows height
hline_top

Set top horizontal border
chunk_dataframe

Create a chunk representation suitable for flextable
highlight

Text highlight color
hyperlink_text

Chunk of text with hyperlink
color

Set font color
merge_none

Delete flextable merging informations
fmt_avg_dev

Format content for mean and sd
merge_at

Merge flextable cells into a single one
merge_v

Merge flextable cells vertically
plot_chunk

Mini plots chunk wrapper
fmt_header_n

Format count data for headers
footers_flextable_at_bkm

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

Set font size
merge_h

Merge flextable cells horizontally
italic

Set italic font
ncol_keys

Number of columns
compose

Define displayed values and mixed content
colorize

Colorize chunk
knit_print.flextable

Render flextable in rmarkdown
continuous_summary

Continuous columns summary
hrule

Set flextable rule for rows heights
prepend_chunks

Prepend chunks to flextable content
rtf_add.flextable

Add a 'flextable' into an RTF document
minibar

Mini barplots chunk wrapper
save_as_html

Save flextable objects in an 'HTML' file
labelizor

Change displayed labels
nrow_part

Number of rows of a part
separate_header

Separate collapsed colnames into multiple rows
line_spacing

Set text alignment
flextable_dim

Get width and height of a flextable object
padding

Set paragraph paddings
plot.flextableGrob

plot a flextable grob
plot.flextable

Plot a flextable
save_as_docx

Save flextable objects in a 'Word' file
set_caption

Set Caption
flextable_html_dependency

htmlDependency for flextable objects
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
save_as_image

Save a flextable in an 'png' file
rotate

Rotate cell text
regulartable

flextable old functions
set_flextable_defaults

Modify flextable defaults formatting properties
footnote

Add footnotes to flextable
set_header_footer_df

Set flextable's header or footer rows
vline

Set vertical borders
vline_left

Set flextable left vertical borders
set_header_labels

Change headers labels
set_table_properties

Global table properties
shift_table

Create a shift table
surround

Set borders for a selection of cells
theme_vanilla

Apply vanilla theme
tabulator

Tabulation of aggregations
fp_border_default

Border formatting properties
theme_zebra

Apply zebra theme
linerange

Mini linerange chunk wrapper
lollipop

Mini lollipop chart chunk wrapper
print.flextable

flextable printing
proc_freq

Frequency table as flextable
vline_right

Set flextable right vertical borders
style

Set flextable style
theme_tron

Apply tron theme
theme_box

Apply box theme
summarizor

Data summary preparation
void

Delete flextable content
theme_tron_legacy

Apply tron legacy theme
theme_vader

Apply Sith Lord Darth Vader theme
use_model_printer

set model automatic printing as a flextable
set_formatter

Set column formatter functions
valign

Set vertical alignment
theme_alafoli

Apply alafoli theme
tabulator_colnames

Column keys of tabulator objects
theme_apa

Apply APA theme
width

Set columns width
to_html.flextable

Get HTML code as a string
theme_booktabs

Apply booktabs theme
use_df_printer

Set data.frame automatic printing as a flextable