Apply formatter functions to column keys.
Functions should have a single argument (the vector) and should return the formatted values as a character vector.
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 = ""
)
a flextable object
Name-value pairs of functions, names should be existing col_key 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 of the table (one of 'body' or 'header' or 'footer') where to apply the formatter functions.
arguments used by sprintf
to
format double and integer columns.
arguments used by format
to
format date and date time columns.
string to be used for logical columns
string for NA values
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()
. Note that we want to deprecate the
set_formatter_type()
function, not the set_formatter()
function.
Other cells formatters:
colformat_char()
,
colformat_date()
,
colformat_datetime()
,
colformat_double()
,
colformat_image()
,
colformat_int()
,
colformat_lgl()
,
colformat_num()
Other cells formatters:
colformat_char()
,
colformat_date()
,
colformat_datetime()
,
colformat_double()
,
colformat_image()
,
colformat_int()
,
colformat_lgl()
,
colformat_num()
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
Sepal.Length
Sepal.Width
Petal.Length
Petal.Width
Species
5.10
3.5000
1.4
0.2
setosa
4.90
3.0000
1.4
0.2
setosa
4.70
3.2000
1.3
0.2
setosa
4.60
3.1000
1.5
0.2
setosa
5.00
3.6000
1.4
0.2
setosa
5.40
3.9000
1.7
0.4
setosa