View source: R/call_derivation.R
call_derivation | R Documentation |
Call a single derivation multiple times with some parameters/arguments being fixed across iterations and others varying.
call_derivation(dataset = NULL, derivation, variable_params, ...)
dataset |
Input dataset |
derivation |
The derivation function to call A function that performs a specific derivation is expected. A derivation
adds variables or observations to a dataset. The first argument of a
derivation must expect a dataset and the derivation must return a dataset.
The function must provide the Please note that it is not possible to specify |
variable_params |
A |
... |
Any number of named function arguments that stay the same across iterations.
If a function argument is specified both inside |
The input dataset with additional records/variables added depending on
which derivation
has been used.
params()
Higher Order Functions:
derivation_slice()
,
restrict_derivation()
,
slice_derivation()
library(dplyr, warn.conflicts = FALSE)
adsl <- tribble(
~STUDYID, ~USUBJID, ~TRTSDT, ~TRTEDT,
"PILOT01", "01-1307", NA, NA,
"PILOT01", "05-1377", "2014-01-04", "2014-01-25",
"PILOT01", "06-1384", "2012-09-15", "2012-09-24",
"PILOT01", "15-1085", "2013-02-16", "2013-08-18",
"PILOT01", "16-1298", "2013-04-08", "2013-06-28"
) %>%
mutate(
across(TRTSDT:TRTEDT, as.Date)
)
ae <- tribble(
~STUDYID, ~DOMAIN, ~USUBJID, ~AESTDTC, ~AEENDTC,
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-23", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-23", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-15", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-23", "2012-09-29",
"PILOT01", "AE", "06-1384", "2012-09-23", "2012-09-29",
"PILOT01", "AE", "16-1298", "2013-06-08", "2013-07-06",
"PILOT01", "AE", "16-1298", "2013-06-08", "2013-07-06",
"PILOT01", "AE", "16-1298", "2013-04-22", "2013-07-06",
"PILOT01", "AE", "16-1298", "2013-04-22", "2013-07-06",
"PILOT01", "AE", "16-1298", "2013-04-22", "2013-07-06",
"PILOT01", "AE", "16-1298", "2013-04-22", "2013-07-06"
)
adae <- ae %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = exprs(TRTSDT, TRTEDT),
by_vars = exprs(USUBJID)
)
## While `derive_vars_dt()` can only add one variable at a time, using `call_derivation()`
## one can add multiple variables in one go
call_derivation(
dataset = adae,
derivation = derive_vars_dt,
variable_params = list(
params(dtc = AESTDTC, date_imputation = "first", new_vars_prefix = "AST"),
params(dtc = AEENDTC, date_imputation = "last", new_vars_prefix = "AEN")
),
min_dates = exprs(TRTSDT),
max_dates = exprs(TRTEDT)
)
## The above call using `call_derivation()` is equivalent to the following
adae %>%
derive_vars_dt(
new_vars_prefix = "AST",
dtc = AESTDTC,
date_imputation = "first",
min_dates = exprs(TRTSDT),
max_dates = exprs(TRTEDT)
) %>%
derive_vars_dt(
new_vars_prefix = "AEN",
dtc = AEENDTC,
date_imputation = "last",
min_dates = exprs(TRTSDT),
max_dates = exprs(TRTEDT)
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.