Skip to contents

Create flextable

These functions create ‘flextable’ objects that can be modified later.

flextable() qflextable()
flextable creation
as_flextable()
Method to transform objects into flextables
flextable-package
flextable: Functions for Tabular Reporting

Global options

Reduce homogenization efforts and the number of functions to be called by defining formatting properties such as font, border color, number of decimal places displayed that should be applied by default.

set_flextable_defaults() init_flextable_defaults()
Modify flextable defaults formatting properties
get_flextable_defaults()
Get flextable defaults formatting properties

Output functions

print(<flextable>)
flextable printing
knit_print(<flextable>)
Render flextable with 'knitr'
body_add_flextable()
Add flextable into a Word document
ph_with(<flextable>)
Add a flextable into a PowerPoint slide
plot(<flextable>)
Plot a flextable
save_as_image()
Save a flextable in a 'png' or 'svg' file
save_as_html()
Save flextable objects in an 'HTML' file
save_as_docx()
Save flextable objects in a 'Word' file
save_as_rtf()
Save flextable objects in an 'RTF' file
save_as_pptx()
Save flextable objects in a 'PowerPoint' file
htmltools_value()
flextable as an 'HTML' object
gen_grob()
Convert a flextable to a grid grob object
plot(<flextableGrob>)
plot a flextable grob
to_html(<flextable>)
Get HTML code as a string
rtf_add(<flextable>)
Add a 'flextable' into an RTF document
flextable_to_rmd()
Knitr rendering in loops and if statements
df_printer()
data.frame automatic printing as a flextable
use_df_printer()
Set data.frame automatic printing as a flextable
use_model_printer()
set model automatic printing as a flextable
body_replace_flextable_at_bkm()
Add flextable at boorkmark location in a Word document

Change visual properties

Modify the visual properties of the components of a ‘flextable’ such as font color, font size, word highlighting or cell background color.

style()
Set flextable style
align() align_text_col() align_nottext_col()
Set text alignment
bg()
Set background color
font()
Set font
fontsize()
Set font size
italic()
Set italic font
bold()
Set bold font
color()
Set font color
line_spacing()
Set text alignment
highlight()
Text highlight color
padding()
Set paragraph paddings
valign()
Set vertical alignment
rotate()
Rotate cell text
tab_settings()
Set tabulation marks configuration
empty_blanks()
Make blank columns as transparent

Management of borders

The border system is based on vertical and horizontal lines which can be easily specified. Some additional tools are provided for specific needs.

fp_border_default()
Border formatting properties
hline()
Set horizontal borders
hline_bottom()
Set bottom horizontal border
hline_top()
Set top horizontal border
vline()
Set vertical borders
vline_left()
Set flextable left vertical borders
vline_right()
Set flextable right vertical borders
border_inner()
Set vertical & horizontal inner borders
border_inner_h()
Set inner borders
border_inner_v()
Set vertical inner borders
border_outer()
Set outer borders
border_remove()
Remove borders
surround()
Set borders for a selection of cells

Flextable themes

Apply theme functions

theme_alafoli()
Apply alafoli theme
theme_apa()
Apply APA theme
theme_booktabs()
Apply booktabs theme
theme_box()
Apply box theme
theme_tron()
Apply tron theme
theme_tron_legacy()
Apply tron legacy theme
theme_vader()
Apply Sith Lord Darth Vader theme
theme_vanilla()
Apply vanilla theme
theme_zebra()
Apply zebra theme

Add headers and footers

Add header titles, comments in footers and new rows in body with the following functions, remove rows and columns.

add_header_row()
Add header labels
add_footer_row()
Add footer labels
add_header_lines()
Add labels as new rows in the header
add_footer_lines()
Add labels as new rows in the footer
add_header()
Add column values as new lines in header
add_footer()
Add column values as new lines in footer
separate_header()
Split column names using a separator into multiple rows
set_header_labels()
Change headers labels
set_header_df() set_footer_df()
Set flextable's header or footer rows
add_body()
Add column values as new lines in body
add_body_row()
Add body labels
delete_part()
Delete flextable part
delete_rows()
Delete flextable rows
delete_columns()
Delete flextable columns

Cell merging

merge_at()
Merge flextable cells into a single one
merge_h()
Merge flextable cells horizontally
merge_h_range()
Rowwise merge of a range of columns
merge_none()
Delete flextable merging informations
merge_v()
Merge flextable cells vertically

flextable dimensions

height() height_all()
Set flextable rows height
set_table_properties()
Global table properties
paginate()
Paginate tables
keep_with_next()
Set Word 'Keep with next' instructions
width()
Set columns width
hrule()
Set flextable rule for rows heights
autofit()
Adjusts cell widths and heights
fit_to_width()
Fit a flextable to a maximum width
dim(<flextable>)
Get widths and heights of flextable
dim_pretty()
Calculate pretty dimensions
flextable_dim()
Get width and height of a flextable object
dim(<flextableGrob>)
Get optimal width and height of a flextable grob
nrow_part()
Number of rows of a part
ncol_keys()
Number of columns

Define how to display the content

Simple tools for formatting the content of cells such as managing the number of decimals, adding suffixes or prefixes and defining the thousands separator.

colformat_char()
Format character cells
colformat_date()
Format date cells
colformat_datetime()
Format datetime cells
colformat_double()
Format numeric cells
colformat_image()
Format cells as images
colformat_int()
Format integer cells
colformat_lgl()
Format logical cells
colformat_num()
Format numeric cells
set_formatter() set_formatter_type()
Set column formatter functions
labelizor()
Change displayed labels

Mixed and complex content

How to define complex paragraphs with mixed content or to add images or chunks of text in existing cells.

compose() mk_par()
Define displayed values and mixed content
as_paragraph()
Concatenate chunks in a flextable
append_chunks()
Append chunks to flextable content
prepend_chunks()
Prepend chunks to flextable content
footnote()
Add footnotes to flextable
fp_text_default()
Text formatting properties

Elements for mixed content

Functions that can be called to create rich, formatted content. They are to be used within calls to mk_par(), append_chunks(), prepend_chunks() and possibly set_caption() functions.

as_chunk()
Chunk of text wrapper
as_image()
Image chunk wrapper
gg_chunk()
'ggplots' chunk wrapper
plot_chunk()
Mini plots chunk wrapper
grid_chunk()
'Grid Graphics' chunk wrapper
as_b()
Bold chunk
as_i()
Italic chunk
as_sub()
Subscript chunk
as_sup()
Superscript chunk
as_highlight()
Highlight chunk
colorize()
Colorize chunk
minibar()
Mini barplots chunk wrapper
linerange()
Mini linerange chunk wrapper
lollipop()
Mini lollipop chart chunk wrapper
as_bracket()
Chunk with values in brackets
hyperlink_text()
Chunk of text with hyperlink
as_equation()
Equation chunk
as_word_field()
'Word' computed field

Caption

set_caption()
Set Caption

miscellaneous

fmt_2stats() fmt_summarizor()
Format content for data generated with summarizor()
fmt_avg_dev()
Format content for mean and sd
fmt_dbl()
Format numerical data
fmt_header_n()
Format count data for headers
fmt_int()
Format numerical data as integer
fmt_n_percent()
Format content for count data
fmt_pct()
Format numerical data as percentages
fmt_signif_after_zeros()
Format with significant figures after zeros
before()
Is an element before a match with entries
void()
Delete flextable content

Transform objects into flextables with ‘as_flextable’

The as_flextable() function is used to transform specific objects into flextable objects. For example, you can transform a crosstab produced with the ‘tables’ package into a flextable which can then be formatted, annotated or augmented with footnotes.

tabulator() summary(<tabulator>)
Tabulation of aggregations
tabulator_colnames()
Column keys of tabulator objects
summarizor()
Data summary preparation
as_flextable()
Method to transform objects into flextables
as_flextable(<data.frame>)
Transform and summarise a 'data.frame' into a flextable Simple summary of a data.frame as a flextable
as_flextable(<gam>)
Transform a 'gam' model into a flextable
as_flextable(<glm>)
Transform a 'glm' object into a flextable
as_flextable(<grouped_data>)
Transform a 'grouped_data' object into a flextable
as_flextable(<htest>)
Transform a 'htest' object into a flextable
as_flextable(<kmeans>)
Transform a 'kmeans' object into a flextable
as_flextable(<lm>)
Transform a 'lm' object into a flextable
as_flextable(<merMod>) as_flextable(<lme>) as_flextable(<gls>) as_flextable(<nlme>) as_flextable(<brmsfit>) as_flextable(<glmmTMB>) as_flextable(<glmmadmb>)
Transform a mixed model into a flextable
as_flextable(<pam>)
Transform a 'pam' object into a flextable
as_flextable(<summarizor>)
Transform a 'summarizor' object into a flextable
as_flextable(<table>)
Transform a 'table' object into a flextable
as_flextable(<tabular>)
Transform a 'tables::tabular' object into a flextable
as_flextable(<tabulator>)
Transform a 'tabulator' object into a flextable
as_flextable(<xtable>)
Transform a 'xtable' object into a flextable
continuous_summary()
Continuous columns summary
as_grouped_data()
Add row separators to grouped data
proc_freq()
Frequency table
shift_table()
Create a shift table