pharmaverse / admiral

ADaM in R Asset Library
https://pharmaverse.github.io/admiral
Apache License 2.0
220 stars 61 forks source link

General Issue: Improve messaging in `derive_extreme_event()` #2405

Closed bundfussr closed 3 months ago

bundfussr commented 4 months ago

Background Information

The messaging in derive_extreme_event() should be improved. Consider the following example.

ad1 <- tribble(
  ~USUBJID, ~AVALC, ~ADY, ~ASEQ,
  "1",      "Y",       3,     1,
  "1",      "Y",       3,     2,
  "2",      "Y",       5,     1,
  "3",      "N",       2,     1,
  "4",      "N",       4,     1
)

ad2 <- tribble(
  ~USUBJID, ~AVALC, ~ADY, ~ASEQ,
  "1",      "Y",       3,     1,
  "2",      "Y",       3,     1,
  "3",      "Y",       2,     1
)

derive_extreme_event(
  by_vars = exprs(USUBJID),
  source_datasets = list(ad1 = ad1, ad2 = ad2),
  order = exprs(event_nr, ADY),
  mode = "first",
  tmp_event_nr_var = event_nr,
  events = list(
    event(
    dataset_name = "ad1",
    condition = AVALC == "Y",
    mode = "first",
    set_values_to = exprs(
      event_nr = 1,
      AVALC = "Y"
    )
    ),
    event(
      dataset_name = "ad2",
      condition = AVALC == "Y",
      mode = "first",
      set_values_to = exprs(
        event_nr = 1,
        AVALC = "Y"
      )
    ),
    event(
      dataset_name = "ad1",
      mode = "last",
      set_values_to = exprs(
        event_nr = 2,
        AVALC = "N"
      )
    )
  )
)

It creates the following warnings.

Warning messages:
1: Dataset contains duplicate records with respect to `USUBJID`, `event_nr` and `ADY`
Run `get_duplicates_dataset()` to access the duplicate records 
2: Dataset contains duplicate records with respect to `USUBJID`, `event_nr` and `ADY`
Run `get_duplicates_dataset()` to access the duplicate records 
3: Dataset contains duplicate records with respect to `USUBJID`, `event_nr` and `ADY`
Run `get_duplicates_dataset()` to access the duplicate records 

That's not user-friendly because

Definition of Done

The function is updated such that the issues mentioned above are resolved.

manciniedoardo commented 4 months ago

Apologies, referenced this issue in a PR by mistake!