-
Notifications
You must be signed in to change notification settings - Fork 80
/
add_header.Rd
82 lines (75 loc) · 2.62 KB
/
add_header.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/augment_rows.R
\name{add_header}
\alias{add_header}
\title{Add column values as new lines in header}
\usage{
add_header(x, top = TRUE, ..., values = NULL)
}
\arguments{
\item{x}{a flextable object}
\item{top}{should the rows be inserted at the top or the bottom.}
\item{...}{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 \code{character} where a \code{double} is expected).
This makes possible to still format cell contents with the \verb{colformat_*}
functions, for example \code{\link[=colformat_num]{colformat_num()}}.}
\item{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 \code{...} for programming purpose (If \code{values} is
supplied argument \code{...} is ignored).}
}
\description{
The function adds a list of values to be inserted as
new rows in the header. 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 header.
If some columns are not provided, they will be replaced by
\code{NA} and displayed as empty.
\if{html}{\out{
<img src="https://www.ardata.fr/img/flextable-imgs/flextable-016.png" alt="add_header illustration" style="width:100\%;">
}}
}
\note{
when repeating values, they can be merged together with
function \code{\link[=merge_h]{merge_h()}} and \code{\link[=merge_v]{merge_v()}}.
}
\examples{
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
}
\seealso{
Other functions for row and column operations in a flextable:
\code{\link{add_body}()},
\code{\link{add_body_row}()},
\code{\link{add_footer}()},
\code{\link{add_footer_lines}()},
\code{\link{add_footer_row}()},
\code{\link{add_header_row}()},
\code{\link{delete_columns}()},
\code{\link{delete_part}()},
\code{\link{delete_rows}()},
\code{\link{separate_header}()},
\code{\link{set_header_footer_df}},
\code{\link{set_header_labels}()}
}
\concept{functions for row and column operations in a flextable}