Learn R Programming

flextable (version 0.7.0)

append_chunks: append chunks to flextable content

Description

append chunks (for example chunk as_chunk()) in a flextable.

Usage

append_chunks(x, i = NULL, j = NULL, ..., part = "body")

Arguments

x

a flextable object

i

rows selection

j

column selection

...

chunks to be appened, see as_chunk(), gg_chunk() and other chunk elements for paragraph.

part

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

Examples

Run this code
# NOT RUN {
library(flextable)

f1 <- function(x) {
  formatC(x, digits = 1,
          format = "f")
}
f2 <- function(x) {
  paste0(
    " (",
    formatC(x, digits = 1,
            format = "f"), ")")
}

ft_1 <- flextable(
  data = head(mtcars),
  col_keys = c("am", "gear", "carb", "mycol")
)
ft_1 <- merge_v(ft_1, j = "am")
ft_1 <- valign(ft_1, valign = "top")
ft_1 <- theme_vanilla(ft_1)
ft_1 <- mk_par(ft_1,
  j = "mycol", part = "body",
  value = as_paragraph(
    as_chunk(mpg, formatter = f1), " ",
    colorize(as_chunk(wt, formatter = f2), "gray")
  )
)

ft_1 <-
  append_chunks(ft_1,
    i = 1, j = "mycol", part = "header",
    as_chunk("mpg "),
    colorize(as_bracket("wt"), "gray")
  )

ft_1 <- align(
  x = ft_1, j = c("am", "gear", "carb"),
  align = "center", part = "all")
ft_1 <- align(
  x = ft_1, j = "mycol",
  align = "right", part = "all")

ft_1 <- autofit(ft_1)

ft_1
# }

Run the code above in your browser using DataLab