assert_list_element: Is an Element of a List of Lists/Classes Fulfilling a...

Description Usage Arguments Author(s) Examples

View source: R/assertions.R

Description

Checks if the elements of a list of named lists/classes fulfill a certain condition. If not, an error is issued and all elements of the list not fulfilling the condition are listed.

Usage

1
assert_list_element(list, element, condition, message_text, ...)

Arguments

list

A list to be checked

A list of named lists or classes is expected.

element

The name of an element of the lists/classes

A character scalar is expected.

condition

Condition to be fulfilled

The condition is evaluated for each element of the list. The element of the lists/classes can be referred to by its name, e.g., censor == 0 to check the censor field of a class.

message_text

Text to be displayed in the message

The text should describe the condition to be fulfilled, e.g., "For events the censor values must be zero.".

...

Objects required to evaluate the condition

If the condition contains objects apart from the element, they have to be passed to the function. See the second example below.

Author(s)

Stefan Bundfuss

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
death <- event_source(
  dataset_name = "adsl",
  filter = DTHFL == "Y",
  date = DTHDT,
  set_values_to = vars(
    EVNTDESC = "DEATH",
    SRCDOM = "ADSL",
    SRCVAR = "DTHDT"
  )
)

lstalv <- censor_source(
  dataset_name = "adsl",
  date = LSTALVDT,
  set_values_to = vars(
    EVNTDESC = "LAST KNOWN ALIVE DATE",
    SRCDOM = "ADSL",
    SRCVAR = "LSTALVDT"
  )
)

try(assert_list_element(
  list = list(death, lstalv),
  element = "censor",
  condition = censor == 0,
  message_text = "For events the censor values must be zero."
))

try(assert_list_element(
  list = events,
  element = "dataset_name",
  condition = dataset_name %in% c("adrs", "adae"),
  valid_datasets = valid_datasets,
  message_text = paste0("The dataset name must be one of the following:\n",
                        paste(valid_datasets, collapse = ", "))
))

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