Skip to contents

Declares an additional row to be inserted above or below rows matching the parent compute_cols() condition. Content can optionally be copied from a specified column; if omitted, creates an empty separator row.

Usage

c_addrow(pos, value_from = NULL, styleRef = NULL)

Arguments

pos

Character. Position for insertion: "above" or "below".

value_from

Unquoted column name or quoted column name string. Optional source column for the inserted row's content (both value_from = PARAM and value_from = "PARAM" are accepted). The value is copied into the FIRST cell of the synthetic row, which spans the full table width. If NULL or missing, creates an empty separator row (a common styled divider idiom).

styleRef

Character vector or result of f_combine(). Optional style to apply to the inserted row. If NULL, no special styling. The inserted row's cell is owned by this styleRef: later c_style() blocks do NOT repaint it (later c_clear()/c_glue() on the source column DO reach it — the synthetic row shares the source cell link).

Value

Quosure structure (internal use within compute_cols())

Details

Must be called inside compute_cols().

Behavior:

  • Multiple c_addrow() calls accumulate; rows are inserted adjacent to the source row, pushing earlier inserts away. Consequence: two inserts in ONE call put the FIRST argument farthest from the source, while two inserts in SEPARATE piped calls put the LATER call closest to the source — stack order is fully controllable via call/argument order.

  • Coexists with other actions on the same row.

  • If value_from is provided, must resolve to exactly one spec column (multi-column selection is an error).

  • If value_from is NULL or missing, creates an empty separator row.

  • With pos = "above" + value_from, the section-header idiom (hide a label column, firstOf() + addrow) builds group headers.

Stackable Actions: Actions within a single compute_cols() call execute sequentially in the order specified: c_addrow() sees values modified by earlier c_glue() actions (the synthetic row copies the ALREADY-GLUED text), allowing compound cell values (e.g., "PARAM: VISIT") in inserted rows.

See also

compute_cols() for conditional row actions, c_style(), c_merge() for other action types

Examples

  lab <- data.frame(
    PARAM = c("ALT", "ALT", "AST"), VISIT = c("W1", "W2", "W1"),
    VAL = c(25, 28, 30), stringsAsFactors = FALSE)
  spec <- create_table(lab) |>
    add_style("grp", s_font(bold = TRUE))

  # Empty separator row above each ALT run
  spec <- compute_cols(spec, firstOf(PARAM), c_addrow(pos = "above"))

  # Section-header row carrying the group value, styled
  spec <- compute_cols(spec, firstOf(PARAM),
    c_addrow(pos = "above", value_from = PARAM, styleRef = "grp"))

  # Stackable: addrow sees the glued value
  spec <- compute_cols(spec, PARAM == "AST",
    c_glue(PARAM, "after", glue_col = VISIT, separator = ": "),
    c_addrow("above", value_from = PARAM))  # inserted row shows "AST: W1"