Postprocessing split function behavior to generally restrict facets
Source:R/make_split_fun.R
restrict_facets.RdPostprocessing 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")
Whetherfacetsnames facets to be (exclusively) kept (the default) or removed.- reorder
(flag)
Forop == "keep", should the resulting facets be reordered to the order they appear infacets. Defaults toTRUE. Ignored ifop == "exclude".- quiet
(logical(1))
Whether warnings should be given or not (the default) when facets named infacetsare not found in the split result.
Value
a function suitable for use within the post argument of
make_split_fun().
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.
See also
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)
#> M F
#> ————————————————————
#> Mean 36.12 33.95
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)
#> F M U
#> ————————————————————————————
#> Mean 33.95 36.12 33.11