clin_spanner_rule: Draw a rule beneath the spanners in a clintable's column...

View source: R/spanner_rule.R

clin_spanner_ruleR Documentation

Draw a rule beneath the spanners in a clintable's column headers

Description

Regulatory arm spanner tables carry a thin horizontal rule directly under each spanner label, running across only the columns that spanner covers, so that the label reads as a heading over its own block of columns. The columns are worked out from the header that is on the table, so the rule follows the spanners as the layout changes instead of having to be given as column numbers that then have to be kept in step with it.

Usage

clin_spanner_rule(x, border = TRUE, rows = NULL)

Arguments

x

A clintable object

border

The pen to draw the rule with. TRUE, the default, draws the 1pt solid black rule these tables conventionally use. An officer::fp_border() draws in whatever width, style and colour it carries, which is how to get a dashed or a hairline rule. FALSE draws no rule, which is how to stop a house style from underlining the spanners.

rows

Header rows to rule, numbered from the top down. NULL, the default, rules every row above the bottom one, so a header of any depth has all of its spanners underlined.

Details

A spanner is a run of header cells that has been merged together, which is what clin_column_headers() makes of adjacent cells holding the same text. Two kinds of run are deliberately left alone:

  • A run of blank cells. That is the empty space over a stub column, or over a trailing p-value column, rather than a spanner - clinify fills the header levels a column does not use, so those cells merge into a run of their own.

  • Anything in the bottom row of the header. That row holds the individual column labels, so a merged run in it is a label sitting over two columns rather than a spanner, and the rule under the bottom row is the one the styling function draws across the whole table.

Called a second time, this refines what the first call set rather than replacing it: arguments this call does not name keep their earlier value.

The rule is drawn as the table renders, after the default styling function has run. That is what makes it survive a house style: the stock clinify_table_default() opens with flextable::border_remove(), which would wipe a border applied any earlier, and a house style is free to draw its header rules in a pen of its own.

Value

A clintable object

Examples

df <- data.frame(
  stub = c("Male", "Female"),
  a_lo = c("5 (10%)", "7 (14%)"),
  a_hi = c("2 (4%)", "3 (6%)"),
  b_lo = c("6 (12%)", "8 (16%)"),
  b_hi = c("1 (2%)", "4 (8%)")
)

ct <- clintable(df, use_labels = FALSE) |>
  clin_column_headers(
    stub = "",
    a_lo = c("Drug A (N=50)", "Low"),
    a_hi = c("Drug A (N=50)", "High"),
    b_lo = c("Drug B (N=50)", "Low"),
    b_hi = c("Drug B (N=50)", "High")
  )

# A rule under each arm spanner, over that arm's two columns only, with the
# stub left un-ruled
clin_spanner_rule(ct)

# The same rule in a dashed pen
clin_spanner_rule(ct, border = officer::fp_border(style = "dashed"))

clinify documentation built on Aug. 2, 2026, 1:06 a.m.