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
- 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 = vars(TRTSDT, TRTEDT),
by_vars = vars(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 = vars(TRTSDT),
max_dates = vars(TRTEDT)
)
#> # A tibble: 1,000 x 7
#> USUBJID AESTDTC AEENDTC TRTSDT TRTEDT ASTDT AENDT
#> <chr> <chr> <chr> <date> <date> <date> <date>
#> 1 01-708-1353 2013-08-… "2013-09-1… 2013-07-04 2013-08-28 2013-08-18 2013-09-10
#> 2 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-13 NA
#> 3 01-701-1287 2014-07-… "2014-07-1… 2014-01-25 2014-07-26 2014-07-09 2014-07-12
#> 4 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-01 NA
#> 5 01-718-1066 2013-07-… "" 2013-07-07 2013-07-16 2013-07-18 NA
#> 6 01-717-1109 2014-02-… "" 2014-01-27 2014-07-28 2014-02-20 NA
#> 7 01-718-1170 2013-10-… "2013-10-1… 2013-09-16 2013-10-12 2013-10-11 2013-10-12
#> 8 01-708-1428 2013-12-… "2013-12-2… 2013-11-09 2013-12-14 2013-12-10 2013-12-21
#> 9 01-705-1349 2013-04-… "2013-04-1… 2013-03-10 2013-09-08 2013-04-11 2013-04-11
#> 10 01-710-1027 2014-05-… "2014-06-2… 2014-02-28 2014-08-29 2014-05-23 2014-06-20
#> # … 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 = vars(TRTSDT),
max_dates = vars(TRTEDT)
) %>%
derive_vars_dt(
new_vars_prefix = "AEN",
dtc = AEENDTC,
date_imputation = "last",
min_dates = vars(TRTSDT),
max_dates = vars(TRTEDT)
)
#> # A tibble: 1,000 x 7
#> USUBJID AESTDTC AEENDTC TRTSDT TRTEDT ASTDT AENDT
#> <chr> <chr> <chr> <date> <date> <date> <date>
#> 1 01-708-1353 2013-08-… "2013-09-1… 2013-07-04 2013-08-28 2013-08-18 2013-09-10
#> 2 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-13 NA
#> 3 01-701-1287 2014-07-… "2014-07-1… 2014-01-25 2014-07-26 2014-07-09 2014-07-12
#> 4 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-01 NA
#> 5 01-718-1066 2013-07-… "" 2013-07-07 2013-07-16 2013-07-18 NA
#> 6 01-717-1109 2014-02-… "" 2014-01-27 2014-07-28 2014-02-20 NA
#> 7 01-718-1170 2013-10-… "2013-10-1… 2013-09-16 2013-10-12 2013-10-11 2013-10-12
#> 8 01-708-1428 2013-12-… "2013-12-2… 2013-11-09 2013-12-14 2013-12-10 2013-12-21
#> 9 01-705-1349 2013-04-… "2013-04-1… 2013-03-10 2013-09-08 2013-04-11 2013-04-11
#> 10 01-710-1027 2014-05-… "2014-06-2… 2014-02-28 2014-08-29 2014-05-23 2014-06-20
#> # … with 990 more rows