Skip to contents

Extracts a specific stratum or subset of strata from the output of plot_sankey(), sankey_counts_table(), or sankey_transition_counts() when a gofl_formula was specified. Supports both full and partial matching: specifying all stratification variables returns the unwrapped result directly (a ggplot or tibble), while specifying only a subset returns a filtered list in the same structure as the input, enabling chaining of multiple filter_gofl() calls.

Usage

filter_gofl(output, ...)

Arguments

output

A named list with var_info and dt elements, as returned by plot_sankey(), sankey_counts_table(), or sankey_transition_counts() when gofl_formula is specified.

...

Named arguments specifying the stratum to extract. Names must match stratification variables used in gofl_formula (e.g., sex = "Male", age_cat = "(40,75]"). Use NA to select the marginal group for a variable (e.g., age_cat = NA returns all patients matching the other filters regardless of age category).

Value

If exactly one stratum matches, returns the unwrapped result: a ggplot object for plot_sankey() output, or a tibble for sankey_counts_table() or sankey_transition_counts()output. If multiple strata match (partial specification), returns a list with var_info and dt in the same structure as the input, which can be passed to another filter_gofl() call. If no strata match, returns a character string indicating no match was found.

Examples

if (FALSE) {
# Full match - returns ggplot directly
plot_sankey(..., gofl_formula = ~ sex * age_cat) |>
  filter_gofl(sex = "Male", age_cat = "(40,75]")

# Partial match - returns filtered list for chaining
plot_sankey(..., gofl_formula = ~ sex * age_cat) |>
  filter_gofl(sex = "Male") |>
  filter_gofl(age_cat = "(40,75]")

# Marginal group - all males regardless of age category
plot_sankey(..., gofl_formula = ~ sex * age_cat) |>
  filter_gofl(sex = "Male", age_cat = NA)
}