Call a single derivation multiple times with some parameters/arguments being fixed across iterations and others varying.
Arguments
- dataset
The 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
dataset
argument and all arguments specified in theparams()
objects passed to thevariable_params
and...
argument.Please note that it is not possible to specify
{dplyr}
functions likemutate()
orsummarize()
.- variable_params
A
list
of function arguments that are different across iterations. Each set of function arguments must be created usingparams()
.- ...
Any number of named function arguments that stay the same across iterations. If a function argument is specified both inside
variable_params
and...
then the value invariable_params
overwrites the one in...
Value
The input dataset with additional records/variables added depending on
which derivation
has been used.
See also
Higher Order Functions:
derivation_slice()
,
restrict_derivation()
,
slice_derivation()
Examples
library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(admiral_ae)
data(admiral_adsl)
adae <-
select(admiral_ae[sample(1:nrow(admiral_ae), 1000), ], USUBJID, AESTDTC, AEENDTC) %>%
derive_vars_merged(
dataset_add = admiral_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)
)
#> # A tibble: 1,000 x 7
#> USUBJID AESTDTC AEENDTC TRTSDT TRTEDT ASTDT AENDT
#> <chr> <chr> <chr> <date> <date> <date> <date>
#> 1 01-713-1179 2013-08-… "2013-09-0… 2013-08-09 2014-02-05 2013-08-28 2013-09-08
#> 2 01-701-1415 2013-10-… "2013-11-0… 2013-09-23 2014-03-24 2013-10-21 2013-11-04
#> 3 01-708-1216 2012-11-… "2012-12-1… 2012-10-24 2012-11-29 2012-11-06 2012-12-13
#> 4 01-710-1368 2014-03-… "" 2013-10-23 2014-04-24 2014-03-26 NA
#> 5 01-709-1029 2013-05-… "2013-05-1… 2012-12-25 2013-06-26 2013-05-12 2013-05-19
#> 6 01-718-1066 2013-07-… "2013-07-2… 2013-07-07 2013-07-16 2013-07-16 2013-07-20
#> 7 01-716-1157 2013-10-… "2013-11-0… 2013-10-02 2014-04-04 2013-10-17 2013-11-04
#> 8 01-701-1192 2012-08-… "2012-09-1… 2012-07-22 2013-01-20 2012-08-07 2012-09-14
#> 9 01-703-1076 2013-11-… "" 2013-10-25 2013-12-24 2013-11-23 NA
#> 10 01-710-1137 2013-11-… "" 2013-10-11 2013-11-13 2013-11-04 NA
#> # … with 990 more rows
## 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)
)
#> # A tibble: 1,000 x 7
#> USUBJID AESTDTC AEENDTC TRTSDT TRTEDT ASTDT AENDT
#> <chr> <chr> <chr> <date> <date> <date> <date>
#> 1 01-713-1179 2013-08-… "2013-09-0… 2013-08-09 2014-02-05 2013-08-28 2013-09-08
#> 2 01-701-1415 2013-10-… "2013-11-0… 2013-09-23 2014-03-24 2013-10-21 2013-11-04
#> 3 01-708-1216 2012-11-… "2012-12-1… 2012-10-24 2012-11-29 2012-11-06 2012-12-13
#> 4 01-710-1368 2014-03-… "" 2013-10-23 2014-04-24 2014-03-26 NA
#> 5 01-709-1029 2013-05-… "2013-05-1… 2012-12-25 2013-06-26 2013-05-12 2013-05-19
#> 6 01-718-1066 2013-07-… "2013-07-2… 2013-07-07 2013-07-16 2013-07-16 2013-07-20
#> 7 01-716-1157 2013-10-… "2013-11-0… 2013-10-02 2014-04-04 2013-10-17 2013-11-04
#> 8 01-701-1192 2012-08-… "2012-09-1… 2012-07-22 2013-01-20 2012-08-07 2012-09-14
#> 9 01-703-1076 2013-11-… "" 2013-10-25 2013-12-24 2013-11-23 NA
#> 10 01-710-1137 2013-11-… "" 2013-10-11 2013-11-13 2013-11-04 NA
#> # … with 990 more rows