Skip to contents

Declares adjacent columns to be merged in rows matching the parent compute_cols() condition. Merged columns appear as a single spanned cell.

Usage

c_merge(cols, styleRef = NULL)

Arguments

cols

Tidyselect expression for column selection. Must resolve to at least 2 columns that are consecutive in the report column order.

styleRef

Character vector or result of f_combine(). Optional style to apply to the merged cell. If NULL, no special styling.

Value

Quosure structure (internal use within compute_cols())

Details

Must be called inside compute_cols(). Columns must be adjacent in the final report column order.

Validation:

  • Immediate: columns exist and are consecutive (error if not)

  • Deferred: overlapping merge ranges within/across compute_cols() calls: a warning is issued and the FIRST-defined merge wins (later overlapping merges are dropped)

Behavior:

  • Multiple merge actions in one row: all applied if non-overlapping

  • The merged cell keeps the LEADER (first) column's text; the other cells are suppressed. A later c_glue() targeting a non-leader merged cell is silently skipped — glue the leader column instead, or merge first via argument order (merge -> clear -> glue is the canonical rebuild idiom).

See also

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

Examples

  spec <- create_table(mtcars) |>
    add_style("group_header", s_table_style(background_color = "#D9D9D9"))

  # Merge two adjacent columns for four-cylinder rows
  spec <- compute_cols(spec, cyl == 4, c_merge(c(mpg, cyl), styleRef = "group_header"))

  # Merge without style
  spec <- compute_cols(spec, cyl == 8, c_merge(c(wt, qsec)))