Add new rows to the body where each value maps to a named column,
preserving the original column data types.
Unlike add_body_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.
Arguments
- 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
characterwhere adoubleis expected). This makes possible to still format cell contents with thecolformat_*functions, for examplecolformat_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 (Ifvaluesis supplied argument...is ignored).
See also
Other functions for row and column operations in a flextable:
add_body_row(),
add_footer(),
add_footer_lines(),
add_footer_row(),
add_header(),
add_header_lines(),
add_header_row(),
delete_columns(),
delete_part(),
separate_header(),
set_header_footer_df,
set_header_labels()
Examples
ft <- flextable(head(iris),
col_keys = c(
"Species", "Sepal.Length", "Petal.Length",
"Sepal.Width", "Petal.Width"
)
)
ft <- add_body(
x = ft, Sepal.Length = 1:5,
Sepal.Width = 1:5 * 2, Petal.Length = 1:5 * 3,
Petal.Width = 1:5 + 10, Species = "Blah", top = FALSE
)
ft <- theme_booktabs(ft)
ft
Species
Sepal.Length
Petal.Length
Sepal.Width
Petal.Width
setosa
5.1
1.4
3.5
0.2
setosa
4.9
1.4
3.0
0.2
setosa
4.7
1.3
3.2
0.2
setosa
4.6
1.5
3.1
0.2
setosa
5.0
1.4
3.6
0.2
setosa
5.4
1.7
3.9
0.4
Blah
1
3
2
11
Blah
2
6
4
12
Blah
3
9
6
13
Blah
4
12
8
14
Blah
5
15
10
15
