add_body: Add column values as new lines in body

View source: R/augment_rows.R

add_bodyR Documentation

Add column values as new lines in body

Description

The function adds a list of values to be inserted as new rows in the body. The values are inserted in existing columns of the input data of the flextable. Rows can be inserted at the top or the bottom of the body.

If some columns are not provided, they will be replaced by NA and displayed as empty.

Usage

add_body(x, top = TRUE, ..., values = NULL)

Arguments

x

a flextable object

top

should the rows be inserted at the top or the bottom.

...

named arguments (names are data colnames) of values to add. It is important to insert data of the same type as the original data, otherwise it will be transformed (probably into strings if you add a character where a double is expected). This makes possible to still format cell contents with the ⁠colformat_*⁠ functions, for example colformat_num().

values

a list of name-value pairs of labels or values, names should be existing col_key values. This argument can be used instead of ... for programming purpose (If values is supplied argument ... is ignored).

See Also

flextable()

Other functions for row and column operations in a flextable: add_body_row(), add_footer_lines(), add_footer_row(), add_footer(), add_header_row(), add_header(), delete_columns(), delete_part(), delete_rows(), separate_header(), set_header_footer_df, set_header_labels()

Examples

ft <- flextable(head(iris),
  col_keys = c(
    "Species", "Sepal.Length", "Petal.Length",
    "Sepal.Width", "Petal.Width"
  )
)

ft <- add_body(
  x = ft, Sepal.Length = 1:5,
  Sepal.Width = 1:5 * 2, Petal.Length = 1:5 * 3,
  Petal.Width = 1:5 + 10, Species = "Blah", top = FALSE
)

ft <- theme_booktabs(ft)
ft

flextable documentation built on Oct. 23, 2023, 1:07 a.m.