split_funcs | R Documentation |
Split functions
remove_split_levels(excl)
keep_split_levels(only, reorder = TRUE)
drop_split_levels(df, spl, vals = NULL, labels = NULL, trim = FALSE)
drop_and_remove_levels(excl)
reorder_split_levels(neworder, newlabels = neworder, drlevels = TRUE)
trim_levels_in_group(innervar, drop_outlevs = TRUE)
excl |
character. Levels to be excluded (they will not be reflected in the resulting table structure regardless of presence in the data). |
only |
character. Levels to retain (all others will be dropped). |
reorder |
logical(1). Should the order of |
df |
dataset ( |
spl |
A Split object defining a partitioning or analysis/tabulation of the data. |
vals |
ANY. For internal use only. |
labels |
character. Labels to use for the remaining levels instead of the existing ones. |
trim |
logical(1). Should splits corresponding with 0 observations be kept when tabulating. |
neworder |
character. New order or factor levels. |
newlabels |
character. Labels for (new order of) factor levels |
drlevels |
logical(1). Should levels in the data which do not appear in
|
innervar |
character(1). Variable whose factor levels should be trimmed (e.g., empty levels dropped) separately within each grouping defined at this point in the structure |
drop_outlevs |
logical(1). Should empty levels in the variable being
split on (i.e. the 'outer' variable, not |
a closure suitable for use as a splitting function (splfun
)
when creating a table layout
User-defined custom split functions can perform any type of computation on the incoming data provided that they meet the contract for generating 'splits' of the incoming data 'based on' the split object.
Split functions are functions that accept:
data.frame of incoming data to be split
a Split object. this is largely an internal detail custom
functions will not need to worry about, but obj_name(spl)
, for
example, will give the name of the split as it will appear in paths in the
resulting table
Any pre-calculated values. If given non-null values, the values returned should match these. Should be NULL in most cases and can likely be ignored
Any pre-calculated value labels. Same as above for
values
If TRUE
, resulting splits that are empty should be
removed
a data.frame describing previously performed
splits which collectively arrived at df
The function must then output a named list
with the following
elements:
The vector of all values corresponding to the splits of
df
a list of data.frames representing the groupings of the
actual observations from df
.
a character vector giving a string label for each value listed
in the values
element above
If present, extra arguments are to be passed to summary
and analysis functions whenever they are executed on the corresponding
element of datasplit
or a subset thereof
One way to generate custom splitting functions is to wrap existing split functions and modify either the incoming data before they are called or their outputs.
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("COUNTRY",
split_fun = remove_split_levels(c("USA", "CAN",
"CHE", "BRA"))) %>%
analyze("AGE")
tbl <- build_table(lyt, DM)
tbl
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("COUNTRY",
split_fun = keep_split_levels(c("USA", "CAN", "BRA"))) %>%
analyze("AGE")
tbl <- build_table(lyt, DM)
tbl
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("SEX", split_fun = drop_split_levels) %>%
analyze("AGE")
tbl <- build_table(lyt, DM)
tbl
lyt <- basic_table() %>%
split_cols_by("ARM") %>%
split_rows_by("SEX", split_fun = drop_and_remove_levels(c("M", "U"))) %>%
analyze("AGE")
tbl <- build_table(lyt, DM)
tbl
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.