| add_header | R Documentation |
Add new rows to the header where each value maps to a named column.
Unlike add_header_row() where labels can span multiple columns,
here each value fills exactly one column.
If some columns are not provided, they will be replaced by
NA and displayed as empty.
add_header(x, top = TRUE, ..., values = NULL)
x |
a 'flextable' object, see flextable-package to learn how to create '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 |
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 |
when repeating values, they can be merged together with
function merge_h() and merge_v().
Other row and column operations:
add_body(),
add_body_row(),
add_footer(),
add_footer_lines(),
add_footer_row(),
add_header_lines(),
add_header_row(),
delete_columns(),
delete_part(),
delete_rows(),
paginate(),
separate_header(),
set_header_footer_df,
set_header_labels(),
split_columns(),
split_rows(),
split_to_pages()
library(flextable)
fun <- function(x) {
paste0(
c("min: ", "max: "),
formatC(range(x))
)
}
new_row <- list(
Sepal.Length = fun(iris$Sepal.Length),
Sepal.Width = fun(iris$Sepal.Width),
Petal.Width = fun(iris$Petal.Width),
Petal.Length = fun(iris$Petal.Length)
)
ft_1 <- flextable(data = head(iris))
ft_1 <- add_header(ft_1, values = new_row, top = FALSE)
ft_1 <- append_chunks(ft_1, part = "header", i = 2, )
ft_1 <- theme_booktabs(ft_1, bold_header = TRUE)
ft_1 <- align(ft_1, align = "center", part = "all")
ft_1
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.