Learn R Programming

rtables (version 0.6.1)

do_base_split: Apply Basic Split (For Use In Custom Split Functions)

Description

This function is intended for use inside custom split functions. It applies the current split as if it had no custom splitting function so that those default splits can be further manipulated.

Usage

do_base_split(spl, df, vals = NULL, labels = NULL, trim = FALSE)

Value

the result of the split being applied as if it had no custom split function, see custom_split_funs

Arguments

spl

A Split object defining a partitioning or analysis/tabulation of the data.

df

dataset (data.frame or tibble)

vals

ANY. Already calculated/known values of the split. Generally should be left as NULL.

labels

character. Labels associated with vals. Should be NULL when vals is, which should almost always be the case.

trim

logical(1). Should groups corresponding to empty data subsets be removed. Defaults to FALSE.

Examples

Run this code

uneven_splfun <- function(df, spl, vals = NULL, labels = NULL, trim = FALSE) {
    ret <- do_base_split(spl, df, vals, labels, trim)
    if(NROW(df) == 0)
        ret <- lapply(ret, function(x) x[1])
    ret
}

lyt <- basic_table() %>%
    split_cols_by("ARM") %>%
    split_cols_by_multivar(c("USUBJID", "AESEQ", "BMRKR1"),
                           varlabels = c("N", "E", "BMR1"),
                           split_fun = uneven_splfun) %>%
    analyze_colvars(list(USUBJID = function(x, ...) length(unique(x)),
                         AESEQ = max,
                         BMRKR1 = mean))

tbl <- build_table(lyt, subset(ex_adae, as.numeric(ARM) <= 2))
tbl

Run the code above in your browser using DataLab