Learn R Programming

flextable (version 0.9.11)

set_formatter: Set column formatter functions

Description

Apply formatter functions to column keys.

Functions should have a single argument (the vector) and should return the formatted values as a character vector.

Usage

set_formatter(x, ..., values = NULL, part = "body")

Arguments

x

a 'flextable' object, see flextable-package to learn how to create 'flextable' object.

...

Name-value pairs of functions, names should be existing col_key values

values

format functions, If values is supplied argument ... is ignored.

  • It can be a list of name-value pairs of functions, names should be existing col_key values.

  • If values is a single function, it will be applied to each column.

part

part selector, see section Part selection with the part parameter in <Selectors in flextable>. Value 'all' is not allowed by the function.

See Also

Other cells formatters: colformat_char(), colformat_date(), colformat_datetime(), colformat_double(), colformat_image(), colformat_int(), colformat_lgl(), colformat_num()

Examples

Run this code
ft <- flextable(head(iris))
ft <- set_formatter(
  x = ft,
  Sepal.Length = function(x) sprintf("%.02f", x),
  Sepal.Width = function(x) sprintf("%.04f", x)
)
ft <- theme_vanilla(ft)
ft

Run the code above in your browser using DataLab