Skip to contents

Declares a glue action to concatenate a value — from a data column or a literal string — to the display text of specified cells in rows matching the parent compute_cols() condition.

Usage

c_glue(cols, position, glue_col = NULL, text = NULL, separator = NULL)

Arguments

cols

Tidyselect expression for the target columns (e.g., col1, c(col1, col2), starts_with("x")). Must resolve to visible (non-hidden) report columns only.

position

Character. Concatenation side: "before" prepends the glue value to the existing cell text; "after" appends it.

glue_col

Optional. Unquoted column name whose formatted value is concatenated onto the target cells. The column may be hidden (not in the visible column list). Mutually exclusive with text.

text

Optional. A single literal character string to concatenate onto the target cells. Mutually exclusive with glue_col.

separator

Character string inserted between the existing cell text and the glued value when both sides are non-empty. Defaults to "" (direct concatenation). When either side is empty, no separator is inserted.

Value

Quosure-style marker (internal use within compute_cols())

Details

Must be called inside compute_cols().

Constraints:

  • Exactly one of glue_col or text must be provided. NOTE: inside compute_cols() actions are parsed from the unevaluated call, so this is enforced only by the interactive c_glue() builder; when BOTH are supplied in a compute_cols() call the parser silently prefers glue_col and ignores text (tracked for a package fix — see Finding-need-further-attention.md U1).

  • cols resolves only visible report columns via tidyselect.

  • glue_col can reference any data column, including hidden ones.

  • glue_col must not overlap with cols.

  • text must be a single string (length > 1 is a hard error).

Behavior:

  • When the glue value (from glue_col or text) is empty or NA, the action is silently skipped for that row/cell.

  • When a target cell was suppressed by deduplication (dedupe = TRUE on that column), the glued text lands on the RAW cell but is not painted (render-level suppression wins) — effectively invisible; glue a non-suppressed column or the first row of each run instead.

  • Glue onto a target cell whose own value is NA renders just the glued part (no \"NA\" text appears).

  • When a target cell is suppressed by a concurrent c_merge() action (i.e., it is a non-leader merged cell), the glue is silently skipped.

  • The merge leader cell is glued normally when c_glue() targets a column involved in c_merge() as the first column.

  • Multiple c_glue() calls on the same column accumulate in call order.

Interaction with other actions:

  • c_style(): Fully compatible — styling and text modification are independent.

  • c_merge(): Compatible. Non-leader (suppressed) merge cells are skipped; the merge-leader cell is glued normally. When a rebuild of a merged total row is intended, keep the canonical argument order merge -> clear -> glue inside ONE compute_cols() call.

  • c_addrow(): Stackable — when used together in the same compute_cols(), c_addrow() sees glued values. This allows building compound cell values (e.g., "PARAM: VISIT") before using them in inserted rows.

  • c_pageBreak(): Fully compatible.

Stackable Actions: Actions within a single compute_cols() call execute sequentially in the order specified. This means c_glue() modifications are visible to subsequent c_addrow() actions in the same call, enabling complex multi-step transformations.

Examples

  lab <- data.frame(
    PARAM = c("ALT", "ALT", "AST"), VISIT = c("W1", "W2", "W1"),
    UNIT  = c("U/L", "U/L", "U/L"), stringsAsFactors = FALSE)
  spec <- create_table(lab) |>
    add_style("bold", s_font(bold = TRUE)) |>
    define_cols(UNIT, isVisible = FALSE)

  # Append a unit from a hidden column
  spec <- compute_cols(spec, TRUE,
    c_glue(PARAM, "after", glue_col = UNIT, separator = " "))

  # Prepend a literal marker
  spec <- compute_cols(spec, PARAM == "AST",
    c_glue(PARAM, "before", text = "*"))

  # Combine with c_style() - independent operations
  spec <- compute_cols(spec, PARAM == "ALT",
    c_glue(VISIT, "before", text = "Visit: "),
    c_style(VISIT, styleRef = "bold"))

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