cond_rm_facets {junco} | R Documentation |
Conditional Removal of Facets
Description
Conditional Removal of Facets
Usage
cond_rm_facets(
facets = NULL,
facets_regex = NULL,
ancestor_pos = 1,
split = NULL,
split_regex = NULL,
value = NULL,
value_regex = NULL,
keep_matches = FALSE
)
Arguments
facets |
character or NULL. Vector of facet names to be removed if condition(s) are met |
facets_regex |
character(1). Regular expression to identify facet names to be removed if condition(s) are met. |
ancestor_pos |
numeric(1). Row in spl_context to check the condition within. E.g., 1 represents the first split, 2 represents the second split nested within the first, etc. NA specifies that the conditions should be checked at all split levels. Negative integers indicate position counting back from the current one, e.g., -1 indicates the direct parent (most recent split before this one). Negative and positive/NA positions cannot be mixed. |
split |
character(1) or NULL. If specified, name of the split
at position |
split_regex |
character(1) or NULL. If specified, a regular expression
the name of the split at position |
value |
character(1) or NULL. If specified, split (facet) value
at position |
value_regex |
character(1) or NULL. If specified, a regular expression
the value of the split at position |
keep_matches |
logical(1). Given the specified condition is met,
should the facets removed be those matching |
Details
Facet removal occurs when the specified condition(s)
on the split(s) and or value(s) are met within at least one
of the split_context rows indicated by ancestor_pos
; otherwise
the set of facets is returned unchanged.
If facet removal is performed, either all facets which match facets
(or
facets_regex
will be removed ( the default keep_matches == FALSE
case), or all non-matching facets will be removed (when
keep_matches_only == TRUE
).
Value
a function suitable for use in make_split_fun
's
post
argument which encodes the specified condition.
Note
A degenerate table is likely to be returned if all facets are removed.
Examples
rm_a_from_placebo <- cond_rm_facets(
facets = "A",
ancestor_pos = NA,
value_regex = "Placeb",
split = "ARM"
)
mysplit <- make_split_fun(post = list(rm_a_from_placebo))
lyt <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by("STRATA1", split_fun = mysplit) |>
analyze("AGE", mean, format = "xx.x")
build_table(lyt, ex_adsl)
rm_bc_from_combo <- cond_rm_facets(
facets = c("B", "C"),
ancestor_pos = -1,
value_regex = "Combi"
)
mysplit2 <- make_split_fun(post = list(rm_bc_from_combo))
lyt2 <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by("STRATA1", split_fun = mysplit2) |>
analyze("AGE", mean, format = "xx.x")
tbl2 <- build_table(lyt2, ex_adsl)
tbl2
rm_bc_from_combo2 <- cond_rm_facets(
facets_regex = "^A$",
ancestor_pos = -1,
value_regex = "Combi",
keep_matches = TRUE
)
mysplit3 <- make_split_fun(post = list(rm_bc_from_combo2))
lyt3 <- basic_table() |>
split_cols_by("ARM") |>
split_cols_by("STRATA1", split_fun = mysplit3) |>
analyze("AGE", mean, format = "xx.x")
tbl3 <- build_table(lyt3, ex_adsl)
stopifnot(identical(cell_values(tbl2), cell_values(tbl3)))