R: set column formatter functions

set_formatter {flextable} | R Documentation

## 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, ..., 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",
      na_str = "")

### Arguments

`x` | a regulartable object
`...` | Name-value pairs of functions, names should be existing col_key values
`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.
`na_str` | string for NA values

### set_formatter_type

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

### Examples

    ft <- regulartable( 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

[Package flextable version 0.4.5 Index]