Skip to main content

Install from CRAN

The stable release of flextable is available on CRAN. Install it with:
install.packages("flextable")
This is the recommended installation for most users.

Install the development version

The development version is hosted on GitHub and may include new features and fixes not yet on CRAN:
# install.packages("devtools")
devtools::install_github("davidgohel/flextable")
The development version may be less stable than the CRAN release. Use it if you need a specific recent fix or feature that has not been released yet.

Dependencies

flextable imports the following packages, which are installed automatically from CRAN:
PackageMinimum versionPurpose
data.table1.13.0Fast internal data manipulation
gdtools0.5.0Font metrics and text rendering
htmltoolsHTML generation
knitrR Markdown / Quarto integration
officer0.7.3Word and PowerPoint document creation
raggHigh-quality PNG rendering
rlangTidy evaluation utilities
rmarkdown2.0R Markdown document rendering
uuid0.1-4Unique identifiers for table elements
xml2XML manipulation for Open XML formats
graphics, grDevices, gridR base graphics
stats, utilsR base utilities

Optional packages

The following packages extend flextable’s capabilities. Install them as needed:
install.packages(c("webshot2", "magick", "pdftools"))
  • webshot2 — save tables as PNG or SVG images
  • magick — image processing
  • pdftools — read and manipulate PDF files
install.packages(c("broom", "broom.mixed", "lme4", "nlme", "mgcv"))
These packages enable as_flextable() to convert model objects from common modelling packages.
install.packages(c("ggplot2", "patchwork", "gtable"))
Use gen_grob() with patchwork to combine flextables and ggplot2 plots in a single figure.
install.packages("officedown")
officedown extends R Markdown with additional Word layout controls and works closely with flextable.
install.packages("bookdown")
Minimum version 0.40. Required for numbered table captions and cross-references in bookdown documents.

Load the package

After installation, load flextable in your R session:
library(flextable)

Check the installed version

packageVersion("flextable")
You can also view the full list of installed metadata:
packageDescription("flextable")

R Markdown setup

flextable works in R Markdown documents without any extra configuration — just load the package in a setup chunk and print the flextable object in a code chunk.
library(flextable)

flextable(head(airquality))
Call set_flextable_defaults() in your setup chunk to apply consistent fonts, sizes, and colors across all tables in the document. This avoids repeating the same formatting calls for every table.
For example, a typical setup chunk looks like this:
```{r setup, include=FALSE}
library(flextable)

set_flextable_defaults(
  font.family = "Arial",
  font.size = 11,
  font.color = "black",
  border.color = "#666666",
  padding = 5,
  table.layout = "autofit"
)
```

Chunk options for captions

flextable supports knitr chunk options for table captions without needing to call set_caption() directly:
```{r}
#| tab.id: tbl-airquality
#| tab.cap: "Air quality measurements, New York, 1973"
flextable(head(airquality))
```
OptionDescription
tab.capCaption text
tab.idCaption bookmark or cross-reference ID
tab.cap.styleWord style name for the caption paragraph
tab.topcaptionDisplay caption above the table (default TRUE)

Verify the installation

Run this snippet to confirm everything is working:
library(flextable)

ft <- flextable(head(mtcars)) |>
  theme_vanilla() |>
  autofit()

ft
If the table renders without errors, your installation is complete.

Next steps

Quickstart

Create and export your first flextable

Global defaults

Set font, color, and layout defaults once for all tables