Create a set of variable parameters/function arguments to be used in call_derivation()
.
See also
Other Advanced Functions:
assert_db_requirements()
,
assert_terms()
,
assert_valid_queries()
,
extend_source_datasets()
,
filter_date_sources()
,
format.basket_select()
,
list_tte_source_objects()
,
validate_basket_select()
,
validate_query()
Examples
library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(admiral_ae)
data(admiral_adsl)
adae <- admiral_ae[sample(1:nrow(admiral_ae), 1000), ] %>%
select(USUBJID, AESTDTC, AEENDTC) %>%
derive_vars_merged(
dataset_add = admiral_adsl,
new_vars = exprs(TRTSDT, TRTEDT),
by_vars = exprs(USUBJID)
)
## In order to derive both `ASTDT` and `AENDT` in `ADAE`, one can use `derive_vars_dt()`
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-705-1292 2014-02-… "" 2013-10-14 2014-05-13 2014-02-13 NA
#> 2 01-710-1045 2013-06-… "2013-06-2… 2013-06-03 2013-08-13 2013-06-22 2013-06-22
#> 3 01-706-1041 2014-01-… "2014-01-2… 2013-12-31 2014-07-28 2014-01-14 2014-01-28
#> 4 01-703-1439 2014-04-… "" 2014-03-12 2014-09-11 2014-04-24 NA
#> 5 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-13 NA
#> 6 01-704-1093 2013-03-… "2013-04-1… 2013-03-15 2013-06-17 2013-03-30 2013-04-13
#> 7 01-708-1428 2013-12-… "2013-12-2… 2013-11-09 2013-12-14 2013-12-10 2013-12-21
#> 8 01-709-1217 2013-03-… "2013-06-1… 2013-03-04 2013-06-11 2013-03-26 2013-06-18
#> 9 01-706-1384 2012-09-… "2012-09-2… 2012-09-15 2012-09-24 2012-09-15 2012-09-29
#> 10 01-708-1347 2013-06-… "2013-06-2… 2013-04-20 2013-06-18 2013-06-13 2013-06-25
#> # … with 990 more rows
## While `derive_vars_dt()` can only add one variable at a time, using `call_derivation()`
## one can add multiple variables in one go.
## The function arguments which are different from a variable to another (e.g. `new_vars_prefix`,
## `dtc`, and `date_imputation`) are specified as a list of `params()` in the `variable_params`
## argument of `call_derivation()`. All other arguments which are common to all variables
## (e.g. `min_dates` and `max_dates`) are specified outside of `variable_params` (i.e. in `...`).
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-705-1292 2014-02-… "" 2013-10-14 2014-05-13 2014-02-13 NA
#> 2 01-710-1045 2013-06-… "2013-06-2… 2013-06-03 2013-08-13 2013-06-22 2013-06-22
#> 3 01-706-1041 2014-01-… "2014-01-2… 2013-12-31 2014-07-28 2014-01-14 2014-01-28
#> 4 01-703-1439 2014-04-… "" 2014-03-12 2014-09-11 2014-04-24 NA
#> 5 01-703-1299 2013-03-… "" 2012-09-12 2013-03-13 2013-03-13 NA
#> 6 01-704-1093 2013-03-… "2013-04-1… 2013-03-15 2013-06-17 2013-03-30 2013-04-13
#> 7 01-708-1428 2013-12-… "2013-12-2… 2013-11-09 2013-12-14 2013-12-10 2013-12-21
#> 8 01-709-1217 2013-03-… "2013-06-1… 2013-03-04 2013-06-11 2013-03-26 2013-06-18
#> 9 01-706-1384 2012-09-… "2012-09-2… 2012-09-15 2012-09-24 2012-09-15 2012-09-29
#> 10 01-708-1347 2013-06-… "2013-06-2… 2013-04-20 2013-06-18 2013-06-13 2013-06-25
#> # … with 990 more rows
## The above call using `call_derivation()` is equivalent to the call using `derive_vars_dt()`
## to derive variables `ASTDT` and `AENDT` separately at the beginning.