Learn R Programming

rtables (version 0.4.0)

custom_split_funs: Custom Split Functions

Split functions provide the work-horse for rtables's generalized partitioning. These functions accept a (sub)set of incoming data, a split object, and return 'splits' of that data.

Description

Custom Split Functions

Split functions provide the work-horse for rtables's generalized partitioning. These functions accept a (sub)set of incoming data, a split object, and return 'splits' of that data.

Arguments

Custom Splitting Function Details

User-defined custom split functions can perform any type of computation on the incoming data provided that they meed the contract for generating 'splits' of the incoming data 'based on' the split object.

Split functions are functions that accept:

df

data.frame of incoming data to be split

spl

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

vals

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

labels

Any pre-calculated value labels. Same as above for values

trim

If TRUE, resulting splits that are empty should be removed

(Optional) .spl_context

a data.frame describing previously performed splits which collectively arrived at df

The function must then output a named list with the following elements:

values

The vector of all values corresponding to the splits of df

datasplit

a list of data.frames representing the groupings of the actual observations from df.

labels

a character vector giving a string label for each value listed in the values element above

(Optional) extras

If present, extra arguments 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.