Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

set_formatter

set column formatter functions


Description

Define formatter functions associated to each column key. Functions have a single argument (the vector) and are returning the formatted values as a character vector.

Usage

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

set_formatter_type(
  x,
  fmt_double = "%.03f",
  fmt_integer = "%.0f",
  fmt_date = "%Y-%m-%d",
  fmt_datetime = "%Y-%m-%d %H:%M:%S",
  true = "true",
  false = "false",
  na_str = ""
)

Arguments

x

a flextable object

...

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

values

a list of name-value pairs of functions, names should be existing col_key values. If values is supplied argument ... is ignored.

part

partname of the table (one of 'body' or 'header' or 'footer')

fmt_double, fmt_integer

arguments used by sprintf to format double and integer columns.

fmt_date, fmt_datetime

arguments used by format to format date and date time columns.

false, true

string to be used for logical columns

na_str

string for NA values

Illustrations

set_formatter_type

set_formatter_type is an helper function to quickly define formatter functions regarding to column types.

This function will be deprecated in favor of the colformat_* functions, for example colformat_double().

See Also

Examples

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

flextable

Functions for Tabular Reporting

v0.6.10
GPL-3
Authors
David Gohel [aut, cre], Clementine Jager [ctb], Quentin Fazilleau [ctb], Maxim Nazarov [ctb] (rmarkdown for docx output), Titouan Robert [ctb], Michael Barrowman [ctb] (inline footnotes), Atsushi Yasumoto [ctb] (support for bookdown cross reference), Paul Julian [ctb] (support for gam objects)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.