Add a row of new columns labels in body part. Labels can be spanned along multiple columns, as merged cells.
Labels are associated with a number of columns to merge that default to one if not specified. In this case, you have to make sure that the number of labels is equal to the number of columns displayed.
The function can add only one single row by call.
a flextable object
should the row be inserted at the top or the bottom.
values to add. It can be a list
or a character()
vector.
If it is a list, it must be a named list using the names of the columns of the
original data.frame or the colkeys
; this is the recommended method because
it allows to keep the original data types and therefore allows to perform
conditional formatting. If a character, columns of the original data.frame
stored in the flextable object are changed to character()
; this is often
not an issue with footer and header but can be inconvenient if adding
rows into body as it will change data types to character and prevent
efficient conditional formatting.
the number of columns to merge in the row for each label
Other functions that add lines in the table:
add_body()
,
add_footer_lines()
,
add_footer_row()
,
add_footer()
,
add_header_row()
,
add_header()
ft <- flextable(head(iris))
ft <- add_body_row(ft, values = list(1000), colwidths = 5)
ft
#> a flextable object.
#> col_keys: `Sepal.Length`, `Sepal.Width`, `Petal.Length`, `Petal.Width`, `Species`
#> header has 1 row(s)
#> body has 7 row(s)
#> original dataset sample:
#> Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1 1000.0 1000.0 1000.0 1e+03 1000
#> 2 5.1 3.5 1.4 2e-01 setosa
#> 3 4.9 3.0 1.4 2e-01 setosa
#> 4 4.7 3.2 1.3 2e-01 setosa
#> 5 4.6 3.1 1.5 2e-01 setosa