Learn R Programming

flextable (version 0.9.11)

labelizor: Replace displayed text with labels

Description

labelizor() substitutes text values shown in a flextable with human-readable labels. This is useful to turn column values such as variable names, factor levels or coded strings into presentation-ready wording (e.g. "Sepal.Length" to "Sepal Length").

labels can be either a named character vector (names identify values to find, values are the replacement labels) or a function applied to every text chunk (e.g. toupper()).

Only the displayed content is affected; the underlying data of the flextable is unchanged.

Usage

labelizor(x, j = NULL, labels, part = "all")

Arguments

x

a 'flextable' object, see flextable-package to learn how to create 'flextable' object.

j

column selector, see section Column selection with the j parameter in <Selectors in flextable>.

labels

a named vector whose names will be used to identify values to replace and values will be used as labels.

part

part selector, see section Part selection with the part parameter in <Selectors in flextable>. Value 'all' can be used.

See Also

mk_par(), append_chunks(), prepend_chunks()

Examples

Run this code
# \dontshow{
data.table::setDTthreads(1)
# }
z <- summarizor(
  x = CO2[-c(1, 4)],
  by = "Treatment",
  overall_label = "Overall"
)

ft_1 <- as_flextable(z, separate_with = "variable")

ft_1 <- labelizor(
  x = ft_1, j = c("stat"),
  labels = c(Missing = "Kouign amann")
)

ft_1 <- labelizor(
  x = ft_1, j = c("variable"),
  labels = toupper
)

ft_1

Run the code above in your browser using DataLab