knit_print.flextable {flextable}R Documentation

Render flextable with 'knitr'

Description

Function used to render flextable in knitr/rmarkdown documents.

You should not call this method directly. This function is used by the knitr package to automatically display a flextable in an "R Markdown" document from a chunk. However, it is recommended to read its documentation in order to get familiar with the different options available.

R Markdown outputs can be :

fig_formats.png

Table captioning is a flextable feature compatible with R Markdown documents. The feature is available for HTML, PDF and Word documents. Compatibility with the "bookdown" package is also ensured, including the ability to produce captions so that they can be used in cross-referencing.

For Word, it's recommanded to work with package 'officedown' that supports all features of flextable.

Usage

## S3 method for class 'flextable'
knit_print(x, ...)

Arguments

x

a flextable object

...

unused.

Chunk options

Some features, often specific to an output format, are available to help you configure some global settings relatve to the table output. knitr's chunk options are to be used to change the default settings:

If some values are to be used all the time in the same document, it is recommended to set these values in a 'knitr r chunk' by using function knitr::opts_chunk$set(ft.split=FALSE, ...).

Table caption

Captions can be defined in two ways.

The first is with the set_caption() function. If it is used, the other method will be ignored. The second method is by using knitr chunk option tab.cap.

set_caption(x, caption = "my caption")

If set_caption function is not used, caption identifier will be read from knitr's chunk option tab.id. Note that in a bookdown and when not using officedown::rdocx_document(), the usual numbering feature of bookdown is used.

tab.id='my_id'.

Some options are available to customise captions for any output:

label name value
Word stylename to use for table captions. tab.cap.style NULL
caption id/bookmark tab.id NULL
caption tab.cap NULL
display table caption on top of the table or not tab.topcaption TRUE
caption table sequence identifier. tab.lp "tab:"

Word output when officedown::rdocx_document() is used is coming with more options such as ability to choose the prefix for numbering chunk for example. The table below expose these options:

label name value
prefix for numbering chunk (default to "Table "). tab.cap.pre Table
suffix for numbering chunk (default to ": "). tab.cap.sep " :"
title number depth tab.cap.tnd 0
caption prefix formatting properties tab.cap.fp_text fp_text_lite(bold = TRUE)
separator to use between title number and table number. tab.cap.tns "-"

HTML output

HTML output is using shadow dom to encapsule the table into an isolated part of the page so that no clash happens with styles.

PDF output

Some features are not implemented in PDF due to technical infeasibility. These are the padding, line_spacing and height properties. Note also justified text is not supported and is transformed to left.

It is recommended to set theses values in a 'knitr r chunk' so that they are permanent all along the document: knitr::opts_chunk$set(ft.tabcolsep=0, ft.latex.float = "none").

See add_latex_dep() if caching flextable results in 'R Markdown' documents.

PowerPoint output

Auto-adjust Layout is not available for PowerPoint, PowerPoint only support fixed layout. It's then often necessary to call function autofit() so that the columns' widths are adjusted if user does not provide the withs.

Images cannot be integrated into tables with the PowerPoint format.

Note

Supported formats require some minimum pandoc versions:

Output format pandoc minimal version
HTML >= 1.12
Word (docx) >= 2.0
PowerPoint (pptx) >= 2.4
PDF >= 1.12

See Also

paginate()

Other flextable print function: as_raster(), df_printer(), flextable_to_rmd(), gen_grob(), htmltools_value(), plot.flextable(), print.flextable(), save_as_docx(), save_as_html(), save_as_image(), save_as_pptx(), save_as_rtf(), to_html.flextable()

Examples

## Not run: 
library(rmarkdown)
if (pandoc_available() &&
  pandoc_version() > numeric_version("2")) {
  demo_loop <- system.file(
    package = "flextable",
    "examples/rmd",
    "demo.Rmd"
  )
  rmd_file <- tempfile(fileext = ".Rmd")
  file.copy(demo_loop, to = rmd_file, overwrite = TRUE)
  render(
    input = rmd_file, output_format = "html_document",
    output_file = "demo.html"
  )
}

## End(Not run)

[Package flextable version 0.9.6 Index]