Skip to contents

Create a set of variable parameters/function arguments to be used in call_derivation().

Usage

params(...)

Arguments

...

One or more named arguments

Value

An object of class params

Author

Thomas Neitmann, Tracey Wang

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 = vars(TRTSDT, TRTEDT),
    by_vars = vars(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 = 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-710-1278 2013-02-… "2013-03-0… 2012-12-24 2013-02-26 2013-02-07 2013-03-03
#>  2 01-709-1029 2013-03-… "2013-04-1… 2012-12-25 2013-06-26 2013-03-20 2013-04-16
#>  3 01-702-1082 2013-09-… "2013-09-0… 2013-07-26 2013-10-13 2013-09-02 2013-09-06
#>  4 01-701-1275 2014-03-… "2014-03-2… 2014-02-07 2014-05-31 2014-03-12 2014-03-27
#>  5 01-713-1256 2012-10-… "2012-10-3… 2012-09-19 2013-03-25 2012-10-30 2012-10-31
#>  6 01-701-1317 2014-06-… ""          2014-05-22 2014-11-20 2014-06-23 NA        
#>  7 01-704-1010 2014-02-… "2014-03-0… 2014-02-21 2014-07-08 2014-02-27 2014-03-06
#>  8 01-705-1292 2014-02-… ""          2013-10-14 2014-05-13 2014-02-13 NA        
#>  9 01-716-1157 2013-10-… "2013-11-0… 2013-10-02 2014-04-04 2013-10-17 2013-11-04
#> 10 01-701-1239 2014-01-… ""          2014-01-11 2014-07-10 2014-01-12 NA        
#> # … 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 = 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-710-1278 2013-02-… "2013-03-0… 2012-12-24 2013-02-26 2013-02-07 2013-03-03
#>  2 01-709-1029 2013-03-… "2013-04-1… 2012-12-25 2013-06-26 2013-03-20 2013-04-16
#>  3 01-702-1082 2013-09-… "2013-09-0… 2013-07-26 2013-10-13 2013-09-02 2013-09-06
#>  4 01-701-1275 2014-03-… "2014-03-2… 2014-02-07 2014-05-31 2014-03-12 2014-03-27
#>  5 01-713-1256 2012-10-… "2012-10-3… 2012-09-19 2013-03-25 2012-10-30 2012-10-31
#>  6 01-701-1317 2014-06-… ""          2014-05-22 2014-11-20 2014-06-23 NA        
#>  7 01-704-1010 2014-02-… "2014-03-0… 2014-02-21 2014-07-08 2014-02-27 2014-03-06
#>  8 01-705-1292 2014-02-… ""          2013-10-14 2014-05-13 2014-02-13 NA        
#>  9 01-716-1157 2013-10-… "2013-11-0… 2013-10-02 2014-04-04 2013-10-17 2013-11-04
#> 10 01-701-1239 2014-01-… ""          2014-01-11 2014-07-10 2014-01-12 NA        
#> # … 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.