restrict_facets: Postprocessing split function behavior to generally restrict...

restrict_facetsR Documentation

Postprocessing split function behavior to generally restrict facets

Description

Postprocessing split function behavior to generally restrict facets

Usage

restrict_facets(
  facets,
  op = c("keep", "exclude"),
  reorder = TRUE,
  quiet = FALSE
)

Arguments

facets

(character)
Vector of facet names

op

⁠("keep", or "exclude")⁠
Whether facets names facets to be (exclusively) kept (the default) or removed.

reorder

(flag)
For op == "keep", should the resulting facets be reordered to the order they appear in facets. Defaults to TRUE. Ignored if op == "exclude".

quiet

(logical(1))
Whether warnings should be given or not (the default) when facets named in facets are not found in the split result.

Details

This is a function factory which creates a post-process behavioral building block for use in make_split_fun().

This factory provides the equivalent of both keep_split_levels and remove_split_levels in a form suitable for use in make_split_fun().

When op is "keep" (the default), resulting facets are restricted to only those named in facets when the generated function is applied to a split result; in the case of "exclude", facets named in facets are removed so that only those not named remain.

The generated function will throw a warning if any of facets are not found in the split result it receives during splitting, unless it was created with quiet = FALSE.

Value

a function suitable for use within the post argument of make_split_fun().

See Also

make_split_fun()

Other make_custom_split: add_combo_facet(), drop_facet_levels(), make_split_fun(), make_split_result(), trim_levels_in_facets()

Examples


keep_spl <- make_split_fun(post = list(restrict_facets(c("M", "F"), op = "keep")))

lyt <- basic_table() |>
  split_cols_by("SEX", split_fun = keep_spl) |>
  analyze("AGE")

build_table(lyt, ex_adsl)


excl_undiff <- restrict_facets("UNDIFFERENTIATED", op = "exclude")
excl_spl <- make_split_fun(post = list(excl_undiff))

lyt <- basic_table() |>
  split_cols_by("SEX", split_fun = excl_spl) |>
  analyze("AGE")

build_table(lyt, ex_adsl)


rtables documentation built on April 27, 2026, 9:09 a.m.