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-701-1111 2012-09-… ""          2012-09-07 2012-09-16 2012-09-13 NA        
#>  2 01-716-1094 2013-01-… ""          2012-12-19 2013-01-24 2013-01-19 NA        
#>  3 01-711-1143 2013-04-… "2013-05-1… 2013-04-03 2013-05-30 2013-04-28 2013-05-11
#>  4 01-715-1405 2013-07-… "2013-07-0… 2013-07-06 2013-07-07 2013-07-08 2013-07-08
#>  5 01-708-1019 2013-12-… "2013-12-3… 2013-12-20 2014-01-01 2013-12-31 2013-12-31
#>  6 01-709-1099 2014-03-… "2014-03-2… 2013-10-25 2014-04-25 2014-03-23 2014-03-23
#>  7 01-704-1017 2013-11-… "2013-11-2… 2013-10-06 2013-11-18 2013-11-05 2013-11-22
#>  8 01-710-1021 2013-10-… "2013-10-1… 2013-09-27 2013-10-29 2013-10-10 2013-10-10
#>  9 01-701-1360 2013-08-… ""          2013-07-31 2013-08-05 2013-08-02 NA        
#> 10 01-711-1143 2013-05-… "2013-06-0… 2013-04-03 2013-05-30 2013-05-28 2013-06-01
#> # … 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-701-1111 2012-09-… ""          2012-09-07 2012-09-16 2012-09-13 NA        
#>  2 01-716-1094 2013-01-… ""          2012-12-19 2013-01-24 2013-01-19 NA        
#>  3 01-711-1143 2013-04-… "2013-05-1… 2013-04-03 2013-05-30 2013-04-28 2013-05-11
#>  4 01-715-1405 2013-07-… "2013-07-0… 2013-07-06 2013-07-07 2013-07-08 2013-07-08
#>  5 01-708-1019 2013-12-… "2013-12-3… 2013-12-20 2014-01-01 2013-12-31 2013-12-31
#>  6 01-709-1099 2014-03-… "2014-03-2… 2013-10-25 2014-04-25 2014-03-23 2014-03-23
#>  7 01-704-1017 2013-11-… "2013-11-2… 2013-10-06 2013-11-18 2013-11-05 2013-11-22
#>  8 01-710-1021 2013-10-… "2013-10-1… 2013-09-27 2013-10-29 2013-10-10 2013-10-10
#>  9 01-701-1360 2013-08-… ""          2013-07-31 2013-08-05 2013-08-02 NA        
#> 10 01-711-1143 2013-05-… "2013-06-0… 2013-04-03 2013-05-30 2013-05-28 2013-06-01
#> # … 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.