
Set flextable defaults from a brand.yml file
Source:R/brand_flextable.R
set_flextable_brand_defaults.Rdset_flextable_brand_defaults() sets flextable::set_flextable_defaults()
from a brand.yml file, so tables created with flextable match the Table
style in a reference document created with brand_reference_docx().
flextable formats each table directly (rather than using the reference
document's Table style), so the defaults are needed for tables to match.
Arguments
- brand
Path to a brand.yml file or a directory containing one, a
brand_ymlobject frombrand.yml::read_brand_yml(), or a list with the brand settings (e.g. fromyaml12::read_yaml()). IfNULL(default), the path is taken from theBRAND_YML_PATHenvironment variable or, if that is not set, found by searching the working directory and its parent directories for_brand.ymlor_brand.yaml, either directly or in abrandor_brandsubdirectory (the same search used by Quarto andbrand.yml::read_brand_yml()).- theme_fun
A flextable theme function applied to each new table, before the
headersettings. Defaults toflextable::theme_box()(borders on every cell, as in the reference documentTablestyle).- ...
Additional arguments passed to
flextable::set_flextable_defaults(). These take precedence over the brand settings.
Value
The previous flextable defaults, invisibly. Pass them to
do.call(flextable::set_flextable_defaults, old) to restore them.
Details
The following brand.yml settings are used:
typography.base:family,size, andline-height(if unitless) for the table text.color.foregroundfor the text color.defaults.docx.styles.Table:border-color,border-width,cell-padding, andheader(family,size,weight,style,color, andbackground-colorfor the header row).
Examples
if (rlang::is_installed(c("flextable", "yaml12"))) {
brand_path <- system.file("extdata", "_brand.yml", package = "officerExtras")
old <- set_flextable_brand_defaults(brand_path)
flextable::flextable(head(mtcars, 3))
do.call(flextable::set_flextable_defaults, old)
}