call_derivation: Call a Single Derivation Multiple Times

Description Usage Arguments Value Author(s) See Also Examples

View source: R/call_derivation.R

Description

Call a single derivation multiple times with some parameters being fixed across iterations and others varying.

Usage

1
call_derivation(dataset = NULL, derivation, variable_params, ...)

Arguments

dataset

The input dataset

derivation

The derivation function to call

variable_params

A list of arguments that are different across iterations. Each set of arguments must be created using params().

...

Any number of named arguments that are fixed across iterations. If a parameter is specified both inside variable_params and ... then the value in variable_params overwrites the one in ...

Value

The input dataset with additional records/variables added depending on which derivation has been used.

Author(s)

Thomas Neitmann, Stefan Bundfuss

See Also

params()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
library(dplyr, warn.conflicts = FALSE)
library(admiral.test)
data(ae)
data(adsl)

adae <- ae[sample(1:nrow(ae), 1000), ] %>%
  left_join(adsl, by = "USUBJID") %>%
  select(USUBJID, AESTDTC, AEENDTC, TRTSDT, TRTEDT)

## 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)
)

## 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)
  )

epijim/admiral documentation built on Feb. 13, 2022, 12:15 a.m.