R: Set flextable's header or footer rows

set_header_footer_df {flextable} | R Documentation

## Set flextable's header or footer rows

### Description

Use a data.frame to specify flextable's header or footer rows.

The data.frame must contain a column whose values match flextable `col_keys` argument, this column will be used as join key. The other columns will be displayed as header or footer rows. The leftmost column is used as the top header/footer row and the rightmost column is used as the bottom header/footer row.

### Usage

    set_header_df(x, mapping = NULL, key = "col_keys")

    set_footer_df(x, mapping = NULL, key = "col_keys")

### Arguments

`x` | a `flextable` object
`mapping` | a `data.frame` specyfing for each colname content of the column.
`key` | column to use as key when joigning data_mapping.

### Examples

    typology <- data.frame(
      col_keys = c( "Sepal.Length", "Sepal.Width", "Petal.Length",
                    "Petal.Width", "Species" ),
      what = c("Sepal", "Sepal", "Petal", "Petal", "Species"),
      measure = c("Length", "Width", "Length", "Width", "Species"),
      stringsAsFactors = FALSE )

    ft <- flextable( head( iris ))
    ft <- set_header_df(ft, mapping = typology, key = "col_keys" )
    ft <- merge_h(ft, part = "header")
    ft <- merge_v(ft, j = "Species", part = "header")
    ft <- theme_vanilla(ft)

    typology <- data.frame(
      col_keys = c( "Sepal.Length", "Sepal.Width", "Petal.Length",
                    "Petal.Width", "Species" ),
      unit = c("(cm)", "(cm)", "(cm)", "(cm)", ""),
      stringsAsFactors = FALSE )
    ft <- set_footer_df(ft, mapping = typology, key = "col_keys" )
    ft <- italic(ft, italic = TRUE, part = "footer" )
    ft <- theme_booktabs(ft)
    ft

[Package flextable version 0.4.5 Index]