tbl_flextable | R Documentation |
Format a data.frame as flextable()
with Certe style, bold headers and Dutch number formats. This function can also transform existing flextable
and gtsummary
objects to allow the formatting provided in this tbl_flextable()
function.
tbl_flextable(
x,
row.names = rownames(x),
row.names.bold = TRUE,
rows.italic = NULL,
rows.bold = NULL,
rows.height = NULL,
rows.fill = NULL,
rows.zebra = TRUE,
row.total = FALSE,
row.total.name = "Totaal",
row.total.function = sum,
row.total.widths = NULL,
row.total.bold = TRUE,
row.extra.header = list(values = NULL, widths = 1),
row.extra.footer = list(values = NULL, widths = 1),
column.names = colnames(x),
column.names.bold = TRUE,
columns.width = NULL,
columns.percent = NULL,
columns.italic = NULL,
columns.bold = NULL,
columns.fill = NULL,
columns.zebra = FALSE,
column.total = FALSE,
column.total.name = "Totaal",
column.total.function = sum,
column.total.bold = TRUE,
align = "c",
align.part = "all",
caption = "",
na = "",
logicals = c("X", ""),
round.numbers = 2,
round.percent = 1,
format.dates = "d mmm yyyy",
decimal.mark = dec_mark(),
big.mark = big_mark(),
font.family = "Source Sans Pro",
font.size = 9,
font.size.header = font.size + 1,
values.colour = NULL,
values.fill = NULL,
values.bold = NULL,
values.italic = NULL,
autofit = is.null(columns.width) & is.null(rows.height),
autofit.fullpage = TRUE,
autofit.fullpage.width = 16,
vline = NULL,
vline.part = c("body", "footer"),
theme = current_markdown_colour(),
colours = list(rows.fill.even = paste0(theme, "6"), rows.fill.odd = paste0(theme, "5"),
columns.fill = paste0(theme, "5"), values.fill = paste0(theme, "3"), values.colour =
theme, vline.colour = theme, hline.colour = theme, header.fill = theme, header.colour
= "white", vline.header.colour = "white"),
split.across.pages = NROW(x) > 37,
print = !interactive(),
...
)
## S3 method for class 'certetoolbox_flextable'
print(x, use_knitr = !is_latex_output(), ...)
x |
a data.frame or a |
row.names |
row names to be displayed. Will be |
row.names.bold |
display row names in bold |
rows.italic |
column indexes of rows in italics |
rows.bold |
column indexes of rows in bold |
rows.height |
height of the rows in centimetres |
rows.fill |
the column indices of rows to be shaded |
rows.zebra |
banded rows in the body - equivalent to |
row.total |
add a row total (at the bottom of the table) |
row.total.name |
name of the row total |
row.total.function |
function used to calculate all numeric values per column (non-numeric columns are skipped) |
row.total.widths |
cell width in row total |
row.total.bold |
bold formatting of row total |
row.extra.header |
an extra header to be displayed above the table |
row.extra.footer |
an extra footer to show below the table |
column.names |
column names to be displayed. Can also be a named vector where the names are existing columns, or indices of columns. When this vector is smaller than |
column.names.bold |
display column names in bold |
columns.width |
width of columns. For |
columns.percent |
display the column indices as percentages using |
columns.italic |
column indices of columns to be displayed in italics |
columns.bold |
column indices of columns in bold |
columns.fill |
the column indices of rows to be shaded |
columns.zebra |
banded columns - equivalent to |
column.total |
adding a column total (to the right of the table) |
column.total.name |
name of the column total |
column.total.function |
function used to calculate all numeric values per row |
column.total.bold |
bold formatting of column total |
align |
default is "c", which aligns everything centrally. Use "r", "l", "c" and "j"/"u" (justify/align) to change alignment. Can be a vector or a character (like "lrrrcc") |
align.part |
part of the table where the alignment should take place ("all", "header", "body", "footer") |
caption |
table caption |
na |
text for missing values |
logicals |
vector with two values that replace |
round.numbers |
number of decimal places to round up for numbers |
round.percent |
number of decimal places to round to when using |
format.dates |
see |
decimal.mark |
decimal separator, defaults to |
big.mark |
thousands separator, defaults to |
font.family |
table font family |
font.size |
table font size |
font.size.header |
font size of header |
values.colour , values.fill , values.bold , values.italic |
values to be formatted |
autofit |
format table in width automatically. This will apply |
autofit.fullpage |
display table across width of page |
autofit.fullpage.width |
set number of centimetres to width of table |
vline |
indices of columns to have a vertical line to their right |
vline.part |
part of the table where the vertical lines should be placed ("all", "header", "body", "footer") |
theme |
a Certe colour theme, defaults to |
colours |
a list with the following named character values: |
split.across.pages |
a logical whether tables are allowed to split across page. This argument only has effect for PDF output. |
print |
forced printing (required in a |
... |
not used |
use_knitr |
use the |
Run tbl_markdown()
on a flextable
object to transform it into markdown for use in Quarto or R Markdown reports. If print = TRUE
in non-interactive sessions (Quarto or R Markdown), the flextable
object will also be printed in markdown.
The value for theme
is dependent on whether a colour is set in the markdown YAML header. Otherwise, use theme
to set a Certe colour theme, defaults to "certeblauw"
:
# from the example below tbl_flextable(df)
tbl_flextable(df, theme = "certeroze")
tbl_flextable(df, theme = "certegeel")
tbl_flextable(df, theme = "certegroen", vline = c(2:3))
tbl_flextable( df, theme = "certelila", row.total = TRUE, row.total.function = median, round.numbers = 4, row.extra.header = list(values = LETTERS[1:5]) )
flextable object
flextable()
## Not run:
# generate a data.frame
df <- data.frame(text = LETTERS[1:10],
`decimal numbers` = runif(10, 0, 10),
`whole numbers` = as.integer(runif(10, 0, 10)),
`logical values` = as.logical(round(runif(10, 0, 1))),
dates = today() - runif(10, 200, 2000),
stringsAsFactors = FALSE)
# default
tbl_flextable(df) # dataset has no row names
tbl_flextable(mtcars) # dataset has row names
# print in markdown
df |>
tbl_flextable() |>
tbl_markdown()
# transform a gtsummary to a flextable
iris |>
tbl_gtsummary(Species, add_p = TRUE) |>
tbl_flextable()
# extra formatting
tbl_flextable(df,
logicals = c("X", "-"), # replaces TRUE en FALSE
values.colour = "X",
values.fill = "X",
row.names = "S. aureus",
columns.italic = 1,
format.dates = "ddd dd-mm-yy",
round.numbers = 3)
# row totals
tbl_flextable(df,
row.total = TRUE, # add row total
row.total.function = max, # instead of sum()
row.total.name = "Maximum", # also works with dates
columns.percent = 2, # 2nd column as percentages
round.percent = 0) # rounding percentages
# column names
tbl_flextable(df,
column.names = c("1" = "Column 1",
"2" = "Column 2",
dates = "DATES!"))
tbl_flextable(df,
column.names = LETTERS)
# vertical lines, alignment and row names
tbl_flextable(df,
align = "lrrcc", # also works: c("l", "r", "r", "c", "c")
font.size = 12,
vline = c(2, 4),
vline.part = "all",
row.names = paste("Experiment", 1:10))
# width of cells and table
tbl_flextable(data.frame(test1 = "A", test2 = "B"),
vline = 1,
autofit.fullpage.width = 16, # default values in cm
columns.width = c(1, 3)) # ratio; cells become 4 and 12 cm
tbl_flextable(data.frame(test1 = "A", test2 = "B"),
vline = 1,
autofit.fullpage = FALSE, # no fullpage autofit
columns.width = c(1, 3)) # cells become 1 and 3 cm
# adding extra header or footer
tbl_flextable(data.frame(test1 = "A", test2 = "B"),
row.extra.header = list(values = c("Header", "Header"),
widths = c(1, 1)),
row.extra.footer = list(values = c("Footer", "Footer"),
widths = c(1, 1)))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.