apply_style: Apply a Style to Table Elements

Description Usage Arguments Details Value See Also

View source: R/apply_style.bare.R

Description

Apply a style to assign graphical properties to table elements. This is an internal function not intended to be called by package users.

Usage

1
apply_style(x, style, replace, setEnabled, unstyled, base_style)

Arguments

x

A data frame containing table elements (entries, hvrules, or blocks).

style

A styleObj object, containing a style appropriate for the type of elements in x.

replace

If FALSE only graphical properties not already present as columns in x are added; existing columns are not changed. If NA, any NA values in existing graphical property columns are replaced with values from style (along with any missing columns). If TRUE then existing columns will be entirely replaced.

setEnabled

If TRUE then column enabled is set to TRUE for elements whose graphical properties are set (or would be set, if replace were TRUE) entirely or in part by style; i.e., elements that match a style row. enabled is not changed for unmatched elements. If FALSE, enabled is not changed for any elements.

unstyled

Character string indicating how to handle elements for which style does not provide graphical parameters (i.e., elements that do not match any style row). One of "pass", "disable", "base", or "error".

base_style

A styleObj object that will be applied to unstyled elements when unstyled="base". This style should be guaranteed to match every element; if it does not an error will be raised.

Details

Table elements include entries, blocks, and hvrules. If x contains table entries, the element_type for style should be "entry". If x contains table blocks, element_type may be either "block" or "hvrule". In the latter case a set of hvrules will be generated, one for each of the four sides of each block. Then style will be used to assign graphical properties to those hvrules.

The graphical properties available for an element, and their types, are defined in function grSpecs and documented in ?elements.

See styleObj for information about how a style is specified, and how it is applied to elements. Note that individual style specifications (rows) in style are applied to x in order. If an element matches more than one style row, the last matching row will override the earlier ones.

NA values after evaluating condition expressions in a style:

styleObj objects contain contain character fields that are evaluated as expressions with respect to columns of x. The fields are called condition for entry and block styles, and block_condition and adjacent_condition for hvrule styles. Each expression must evaluate to a logical scalar or vector with one value per row of x. If an expression evaluates to NA for a row of x it is treated as FALSE for that row–the reason to not throw an error is to make it easier to manually add blocks or hvrules by position only. (Note that this is different from the case where the condition expression itself, before evaluation, is NA. The latter is treated as evaluating to TRUE for all rows of x.)

Value

A data frame. It has one row per table element and the same columns as x, plus additional or updated columns containing the graphical properties to use for each element, plus a column style_row (the number of the last row in style that the entry matched, or NA if it matched none).

See Also

styleObj; grSpecs, apply_scale


tablesgg documentation built on June 3, 2021, 1:06 a.m.