flextable (version 0.5.5)

add_header: Add a rows of labels in header or footer part

Description

Add rows of labels in the flextable's header or footer part. It can be inserted at the top or the bottom of the part. The function is column oriented, labels are specified for each columns, there can be more than a label - resulting in more than a new row.

Usage

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

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

Arguments

x

a flextable object

top

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

...

a named list (names are data colnames) of strings specifying corresponding labels to add.

values

a list of name-value pairs of labels or values, names should be existing col_key values. If values is supplied argument ... is ignored.

See Also

Other headers and footers: add_header_lines, add_header_row, set_header_footer_df

Examples

Run this code
# NOT RUN {
ft <- flextable( head( iris ),
   col_keys = c("Species", "Sepal.Length", "Petal.Length",
                "Sepal.Width", "Petal.Width") )

# start with no header
ft <- delete_part(ft, part = "header")

# add a line of row
ft <- add_header(x = ft, Sepal.Length = "length",
   Sepal.Width = "width", Petal.Length = "length",
   Petal.Width = "width", Species = "Species", top = FALSE )
# add another line of row at the top position
ft <- add_header(ft, Sepal.Length = "Inches",
   Sepal.Width = "Inches", Petal.Length = "Inches",
   Petal.Width = "Inches", top = TRUE )
# merge horizontally when there are identical values
ft <- merge_h(ft, part = "header")


# add a footnote in the footer part
ft <- add_footer(ft, Species = "This is a footnote" )
ft <- merge_at(ft, j = 1:5, part = "footer")

# theme the table
ft <- theme_box(ft)

ft
# }

Run the code above in your browser using DataLab