colformat_* functions apply display formatting to columns based on their data type. They all target the body part by default and use the values from get_flextable_defaults() for their default arguments.
colformat_double()
Format double (floating-point numeric) columns usingformatC().
A
flextable object.Row selector.
NULL selects all rows.Column selector. Only columns of type
double are affected; other column types are silently skipped.Thousands separator. See
formatC(). Defaults to the value in set_flextable_defaults().Decimal separator. See
formatC(). Defaults to the value in set_flextable_defaults().Number of digits after the decimal point. See
formatC(). Defaults to the value in set_flextable_defaults().String displayed for
NA values.String displayed for
NaN values.String prepended to every formatted value.
String appended to every formatted value.
Example
colformat_int()
Format integer columns.Thousands separator. See
format().Example
colformat_num()
Format numeric columns using R’sformat() function, matching typical R console output. Scientific notation is disabled and NA values are replaced.
...
Additional arguments passed to
format(). Note: scientific and digits cannot be used.Example
colformat_char()
Format character and factor columns.Example
colformat_lgl()
Format logical columns.String displayed for
TRUE values.String displayed for
FALSE values.Example
colformat_date()
FormatDate columns.
Date format string passed to
strptime(). Defaults to "%Y-%m-%d" unless overridden with set_flextable_defaults().Example
colformat_datetime()
FormatPOSIXct / POSIXlt (datetime) columns.
Datetime format string passed to
strptime(). Defaults to "%Y-%m-%d %H:%M:%S" unless overridden with set_flextable_defaults().Example
colformat_image()
Render character columns that contain image file paths as inline images.Image display width in inches.
Image display height in inches.
Example
set_formatter()
Apply custom formatter functions to specified columns. Each formatter receives a vector of column values and must return a character vector.A
flextable object.Named arguments where names are column keys and values are single-argument formatter functions.
A named list of formatter functions (names are column keys), or a single function applied to every column. If supplied,
... is ignored.Which part to apply formatting to:
"body", "header", or "footer". The value "all" is not allowed.Example
Return value
All functions return the modifiedflextable object.
See also
set_flextable_defaults()— set global defaults for marks, digits, and NA stringscompose()— full control over cell content withas_paragraph()as_chunk()— formatted text chunks