compose: Define displayed values and mixed content

View source: R/compose.R

composeR Documentation

Define displayed values and mixed content

Description

Modify flextable displayed values with eventually mixed content paragraphs.

Function is handling complex formatting as image insertion with as_image(), superscript with as_sup(), formated text with as_chunk() and several other chunk functions.

Function mk_par is another name for compose as there is an unwanted conflict with package 'purrr'.

If you only need to add some content at the end or the beginning of paragraphs and keep existing content as it is, functions append_chunks() and prepend_chunks() should be prefered.

Usage

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)

Arguments

x

a flextable object

i

rows selection

j

column selection

value

a call to function as_paragraph().

part

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

use_dot

by default use_dot=FALSE; if use_dot=TRUE, value is evaluated within a data.frame augmented of a column named . containing the jth column.

See Also

fp_text_default(), as_chunk(), as_b(), as_word_field(), labelizor()

Other functions for mixed content paragraphs: append_chunks(), as_paragraph(), prepend_chunks()

Examples

ft_1 <- flextable(head(cars, n = 5), col_keys = c("speed", "dist", "comment"))
ft_1 <- mk_par(
  x = ft_1, j = "comment",
  i = ~ dist > 9,
  value = as_paragraph(
    colorize(as_i("speed: "), color = "gray"),
    as_sup(sprintf("%.0f", speed))
  )
)
ft_1 <- set_table_properties(ft_1, layout = "autofit")
ft_1

# using `use_dot = TRUE` ----
set.seed(8)
dat <- iris[sample.int(n = 150, size = 10), ]
dat <- dat[order(dat$Species), ]


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

flextable documentation built on Oct. 30, 2024, 9:15 a.m.