build_def {healthdb} | R Documentation |
Build case definition function calls
Description
This function assembles function calls from the supplied functions and their required arguments, leaving the data argument empty for easy re-use of the definition calls with different data and batch execution (see execute_def()
for detail). It is useful for defining multiple diseases/events across multiple sources.
Usage
build_def(def_lab, src_labs, def_fn = define_case, fn_args)
Arguments
def_lab |
A single character label for the definition, e.g., some disease. |
src_labs |
A character vector of place-holder names for the data sources that will be used to execute the definition. |
def_fn |
A list of functions (default: |
fn_args |
A named list of arguments passing to the |
Value
A tibble with a number of rows equal to the length of src_labs
, containing the input arguments and the synthetic function call in the fn_call
column.
Examples
sud_def <- build_def("SUD", # usually a disease name
src_lab = c("src1", "src2"), # identify from multiple sources, e.g., hospitalization, ED visits.
# functions that filter the data with some criteria,
# including mean here for src2 as a trivial example
# to show only valid arguments will be in the call
def_fn = list(define_case, mean),
fn_args = list(
vars = list(starts_with("diagx"), "diagx_2"),
match = "start", # "start" will be applied to all sources as length = 1
vals = list(c("304"), c("305")),
clnt_id = "clnt_id",
# c() can be used in place of list
# if this argument only takes one value for each source
n_per_clnt = c(2, 3),
x = list(1:10) # src2 with mean as def_fn will only accept this argument
)
)
# the result is a tibble
sud_def
# the fn_call column stores the code that can be ran with execute_def
sud_def#fn_call