Skip to contents

This function converts a named numeric vector model representing signature contributions to a formatted string. By default, contributions are displayed as percentages, with options to customize formatting. Unexplained portions of the model (i.e., contributions not accounted for by the signatures) can be optionally displayed.

Usage

sig_model_to_string(
  model,
  signature_sep = " = ",
  pair_sep = " | ",
  show_percent = TRUE,
  significant_digits = 2,
  include_unexplained = TRUE,
  unexplained_label = "?"
)

Arguments

model

A named numeric vector representing the contribution of each signature to the combined model. The names correspond to the signatures, and the values represent their contributions. The sum of the values in this vector should be less than or equal to 1.

signature_sep

A character string used to separate each signature name from its value (default is " = ").

pair_sep

A character string used to separate different signatures (default is " | ").

show_percent

A logical indicating whether to format values as percentages (default is TRUE).

significant_digits

The number of significant digits to display for the contributions (default is 2).

include_unexplained

A logical flag indicating whether to include the unexplained portion of the model (default is TRUE).

unexplained_label

A character string to label the unexplained portion of the model (default is "?").

Value

A string representing the signature model with contributions formatted according to the specified options.

Examples

model <- c(SBS1 = 0.4, SBS2 = 0.6)
sig_model_to_string(model)
#> [1] "SBS2 = 60% | SBS1 = 40% | ? = 0%"

# Example with no unexplained portion, significant digits and percentages
sig_model_to_string(
  model,
  significant_digits = 3,
  show_percent = FALSE,
  include_unexplained = FALSE
  )
#> [1] "SBS2 = 0.6 | SBS1 = 0.4"