Skip to main content
compose() and mk_par() are identical functions that set the displayed content of selected cells using paragraph chunks. They handle complex formatting such as inline images, superscripts, formatted text, and hyperlinks.
mk_par() is an alias for compose() introduced to avoid a naming conflict with purrr::compose(). Prefer mk_par() in projects that use purrr.

Function signature

compose(x, i = NULL, j = NULL, value, part = "body", use_dot = FALSE)

mk_par(x, i = NULL, j = NULL, value, part = "body", use_dot = FALSE)

Parameters

x
flextable
required
A flextable object.
i
integer | formula | logical
Row selector. Accepts integer indices, a one-sided formula (e.g., ~ dist > 9), or a logical vector. NULL selects all rows.
j
integer | character | formula
Column selector. Accepts integer indices, column names, a formula, or a logical vector.
value
paragraph
required
A call to as_paragraph() defining the new cell content.
part
string
default:"body"
Which part of the table to target: "body", "header", "footer", or "all".
use_dot
logical
default:"FALSE"
If TRUE, the value expression is evaluated in a data frame augmented with a column named . containing the values of the jth column. This enables column-referencing syntax like minibar(., ...) or as_chunk(.) inside as_paragraph().

Return value

The modified flextable object.

Examples

Add formatted text with a superscript to a specific column, targeting rows conditionally:
ft <- flextable(head(cars, n = 5), col_keys = c("speed", "dist", "comment"))
ft <- mk_par(
  x = ft,
  j = "comment",
  i = ~ dist > 9,
  value = as_paragraph(
    colorize(as_i("speed: "), color = "gray"),
    as_sup(sprintf("%.0f", speed))
  )
)
ft <- set_table_properties(ft, layout = "autofit")
ft
Use use_dot = TRUE to reference the column’s own values inside as_paragraph():
set.seed(8)
dat <- iris[sample.int(n = 150, size = 10), ]
dat <- dat[order(dat$Species), ]

ft <- flextable(dat)
ft <- mk_par(
  ft,
  j = ~ . - Species,
  value = as_paragraph(
    minibar(., barcol = "white", height = .1)
  ),
  use_dot = TRUE
)
ft <- theme_vader(ft)
ft <- autofit(ft)
ft

See also