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.

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

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

Arguments

x

a flextable object

top

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

...

a named list (names are data colnames) of strings specifying corresponding 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 keeps the ability to 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).

Note

when repeating values, they can be merged together with function merge_h() and merge_v().

Illustrations

See also

Examples

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 note in footer" ) ft <- merge_at(ft, j = 1:5, part = "footer") # theme the table ft <- theme_box(ft) ft
#> a flextable object. #> col_keys: `Species`, `Sepal.Length`, `Petal.Length`, `Sepal.Width`, `Petal.Width` #> header has 2 row(s) #> body has 6 row(s) #> original dataset sample: #> Sepal.Length Sepal.Width Petal.Length Petal.Width Species #> 1 5.1 3.5 1.4 0.2 setosa #> 2 4.9 3.0 1.4 0.2 setosa #> 3 4.7 3.2 1.3 0.2 setosa #> 4 4.6 3.1 1.5 0.2 setosa #> 5 5.0 3.6 1.4 0.2 setosa