flextable (version 0.5.1)

display: Define flextable displayed values

Description

Modify flextable displayed values by specifying a string expression. Function is handling complex formatting as well as image insertion.

Usage

display(x, i = NULL, col_key, pattern, formatters = list(),
  fprops = list(), part = "body")

Arguments

x

a flextable object

i

rows selection

col_key

column to modify, a single character

pattern

string to format

formatters

a list of formula, left side for the name, right side for the content.

fprops

a named list of fp_text

part

partname of the table (one of 'all', 'body', 'header', 'footer')

pattern

It defined the template used to format the produced strings. Names enclosed by double braces will be evaluated as R code, the corresponding R code is defined with the argument formatters.

formatters

Each compound is specifying the R code to execute to produce strings that will be substituted in the pattern argument. An element must be a formula: the left-hand side is a name (matching a name enclosed by double braces in pattern) and the right-hand side is an R expression to be evaluated (that will produce the corresponding strings).

The function is designed to work with columns in the dataset provided to flextable (the col_keys).

fprops

A named list of fp_text. It defines the formatting properties associated to a compound in formatters. If not defined for an element of formatters, the default formatting properties will be applied.

Examples

Run this code
# NOT RUN {
library(officer)
# Formatting data values example ------
ft <- flextable(head( mtcars, n = 10))
ft <- display(ft, col_key = "carb",
  i = ~ drat > 3.5, pattern = "# {{carb}}",
  formatters = list(carb ~ sprintf("%.1f", carb)),
  fprops = list(carb = fp_text(color="orange") ) )
# }
# NOT RUN {
ft <- autofit(ft)
# }

Run the code above in your browser using DataLab