A function that accepts tabular data, in a range of formats, and outputs an object of class flextable() (intended) for display in html and word documents.
Usage
thekids_table(
x,
font.size = 10,
font.size.header = 11,
line.spacing = 1.5,
padding = 2.5,
colour = "CoolGrey",
zebra = FALSE,
highlight = NULL,
font_family = "Barlow",
fallback_font_family = "sans",
date_fix = TRUE,
...
)Arguments
- x
a table, typically a data.frame, tibble, or output from gtsummary.
- font.size
the font size for text in the body of the table, defaults to 8 (passed through to set_flextable_defaults).
- font.size.header
the font size for text in the header of the table, defaults to 10.
- line.spacing
line spacing for the table, defaults to 1.5 (passed through to set_flextable_defaults).
- padding
padding around all four sides of the text within the cell, defaults to 2.5 (passed through to set_flextable_defaults).
- colour
a colour palette from The Kids branding, options include "Saffron", "Pumpkin", "Teal", "DarkTeal", "CelestialBlue", "AzureBlue", "MidnightBlue", or "CoolGrey", defaults to 'CoolGrey'.
- zebra
controls alternating highlighting of rows, logical or integer (defaults to
F); if TRUE, alternate each row's background withcolour; if an integer, alternate row blocks of this size are highlighted; if negative, this will invert the sequence of highlighted blocks; (defaults toF)- highlight
a numeric vector indicating which rows are to receive a colour highlight, based on the selected colouring (defaults to
NULLgiving no highlighted rows).- font_family
string containing the font family to apply to the table. Default "Barlow".
- fallback_font_family
fallback font family if
font_familyis does not exist. Default is "sans".- date_fix
re-wraps date objects to strictly occupy one line, instead of splitting (defaults to
T).- ...
other parameters passed through to
set_flextable_defaults.
Details
The purpose of this function is easily coerce many different table structures in a consistent format (look and feel), with The Kids branding applied, that ultimately will look nice in either an html or word output.
Default settings produce a relatively compact table, to avoid reports becoming excessively lengthy.
The output can be piped (%>%) into further flextable() functions for advance customisation of the appearance.
Currently the function works well with input in the form of data frames, tibbles, dplyr pipes (think summarise()), gtsummary, and kable outputs.
For a more thorough example, see the vignette.
Note
Errors may be encountered if the input to the function (kable/gtsummary/flextable) has already received a lot of processing (merging cells, aesthetic changes). The intention is that these things would occur after running thekids_table().
Font family must be installed at a system level, otherwise the default ("sans") will be applied.
Pre-specified formatting applied to 'flextable' objects (ahead of thekids_table()) may not carry over as expected. Please consider using thekids_table() in place of an explicit flextable() call, because our function already coerces the table to a flextable object.
Examples
if (FALSE) { # \dontrun{
head(mtcars, 10) %>%
thekids_table(colour = "Saffron")
mtcars %>%
select(cyl, mpg, hp, wt, gear) %>%
group_by(cyl, gear) %>%
summarise(mean_mpg = mean(mpg),
mean_hp = mean(hp),
mean_wt = mean(wt)) %>%
thekids_table(colour = "CelestialBlue", highlight = c(4:6),
padding.left = 20, padding.right = 20)
} # }
