frmt | R Documentation |
These functions provide an abstracted way to approach to define formatting of table contents. By defining in this way, the formats can be layered to be more specific and general cell styling can be done first.
frmt()
is the base definition of a format. This defines spacing, rounding,
and missing behaviour.
frmt_combine()
is used when two or more rows need to be combined into a
single cell in the table. Each of the rows needs to have a defined frmt()
and need to share a label.
frmt_when()
is used when a rows format behaviour is dependent on the value itself and is written similarly to dplyr::case_when()
.
The left hand side of the equation is a "TRUE"
for the default case or the right hand side of a boolean expression ">50"
.
frmt(expression, missing = NULL, scientific = NULL, transform = NULL, ...)
frmt_combine(expression, ..., missing = NULL)
frmt_when(..., missing = NULL)
expression |
this is the string representing the intended format. See details: expression for more a detailed description. |
missing |
when a value is missing that is intended to be formatted, what value to place. See details: missing for more a detailed description. |
scientific |
a string representing the intended scientific notation to be appended to the expression. Ex. "e^XX" or " x10^XX". |
transform |
this is what should happen to the value prior to formatting,
It should be a formula or function. Ex. |
... |
See details: |
frmt()
All numbers are represented by "x". Any additional character are
printed as-is. If additional X's present to the left of the decimal point
than the value, they will be represented as spaces.
frmt_combine()
defines how the parameters will be combined as a
glue::glue()
statement. Parameters need to be equal to the values in the
param column and defined in the expression as "{param1} {param2}"
.
frmt()
Value to enter when the value is missing. When NULL, the value
is "".
frmt_combine()
defines how when all values to be combined are missing.
When NULL the value is "".
frmt()
These dots are for future extensions and must be
empty.
frmt_combine()
accepts named arguments defining the frmt()
to
be applied to which parameters before being combined.
frmt_when()
accepts a series of equations separated by commas, similar
to dplyr::case_when()
. The left hand side of the equation is a "TRUE"
for the
default case or the right hand side of a boolean expression ">50"
. The
right hand side of the equation is the frmt()
to apply when the left
side evaluates to TRUE
.
frmt object
body_plan()
combines the frmt_structures to be applied to the
table body, and frmt_structure()
defines which rows the formats will be applied
to.
frmt("XXX %")
frmt("XX.XXX")
frmt("xx.xx", scientific = "x10^xx")
frmt_combine(
"{param1} {param2}",
param1 = frmt("XXX %"),
param2 = frmt("XX.XXX")
)
frmt_when(
">3" ~ frmt("(X.X%)"),
"<=3" ~ frmt("Undetectable")
)
frmt_when(
"==100"~ frmt(""),
"==0"~ "",
"TRUE" ~ frmt("(XXX.X%)")
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.