-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathael03.R
More file actions
129 lines (124 loc) · 4.45 KB
/
Copy pathael03.R
File metadata and controls
129 lines (124 loc) · 4.45 KB
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# ael03_main ----
#' @describeIn ael03 Main TLG function
#'
#' @inheritParams gen_args
#' @param dataset (`string`) the name of a table in the `adam_db` object.
#' @param default_formatting (`list`) the default format of the listing columns. See [`rlistings::as_listing`].
#' @param col_formatting (`list`) the format of specific listing columns. See [`rlistings::as_listing`].
#'
#' @export
#'
ael03_main <- function(adam_db,
dataset = "adae",
arm_var = "ACTARM",
key_cols = c("ID", "ASR", arm_var),
disp_cols = c(
"AEDECOD", "TRTSDTM", "ASTDY", "ADURN", "AESEV",
"AEREL", "AEOUT", "AECONTRT", "ACTION", "SERREAS"
),
default_formatting = list(
all = fmt_config(align = "left"),
numeric = fmt_config(align = "center"),
Date = fmt_config(format = format_date(), align = "left"),
POSIXct = fmt_config(format = format_date(), align = "left"),
POSIXt = fmt_config(format = format_date(), align = "left")
),
unique_rows = TRUE,
...) {
assert_all_tablenames(adam_db, dataset)
assert_valid_variable(adam_db[[dataset]], c(arm_var, key_cols, disp_cols), label = paste0("adam_db$", dataset))
assert_list(default_formatting, types = "fmt_config", names = "unique")
assert_flag(unique_rows)
execute_with_args(
as_listing,
adam_db[[dataset]],
key_cols = key_cols,
disp_cols = disp_cols,
default_formatting = default_formatting,
unique_rows = unique_rows,
...
)
}
#' @describeIn ael03 Preprocessing
#'
#' @inheritParams ael03_main
#'
#' @export
#'
ael03_pre <- function(adam_db,
dataset = "adae",
arm_var = "ACTARM",
...) {
adam_db[[dataset]] <- adam_db[[dataset]] %>%
filter(.data$ANL01FL == "Y") %>%
filter(.data$AESER == "Y") %>%
mutate(
across(
all_of(c(arm_var, "AEDECOD", "AESEV", "AEOUT", "AEACN")),
~ reformat(.x, missing_rule)
)
) %>%
mutate(
ID = create_id_listings(.data$SITEID, .data$SUBJID),
ASR = with_label(paste(.data$AGE, .data$SEX, .data$RACE, sep = "/"), "Age/Sex/Race"),
TRTSDTM = with_label(
.data$TRTSDTM,
"Date of\nFirst Study\nDrug\nAdministration"
),
ADURN = with_label(.data$AENDY - .data$ASTDY + 1, "AE\nDuration\nin Days"),
AEREL = with_label(
reformat(.data$AEREL, yes_no_rule),
"Caused by\nStudy\nDrug"
),
AEOUT = with_label(case_when(
AEOUT == "FATAL" ~ 1,
AEOUT == "NOT RECOVERED/NOT RESOLVED" ~ 2,
AEOUT == "RECOVERED/RESOLVED" ~ 3,
AEOUT == "RECOVERED/RESOLVED WITH SEQUELAE" ~ 4,
AEOUT == "RECOVERING/RESOLVING" ~ 5,
AEOUT == "UNKNOWN" ~ 6
), "Outcome\n(1)"),
AECONTRT = with_label(
reformat(.data$AECONTRT, yes_no_rule),
"Treatment\nfor AE"
),
ACTION = with_label(case_when(
AEACN == "DOSE INCREASED" ~ 1,
AEACN == "DOSE NOT CHANGED" ~ 2,
AEACN == "DOSE REDUCED" | AEACN == "DOSE RATE REDUCED" ~ 3,
AEACN == "DRUG INTERRUPTED" ~ 4,
AEACN == "DRUG WITHDRAWN" ~ 5,
AEACN == "NOT APPLICABLE" | AEACN == "NOT EVALUABLE" ~ 6,
AEACN == "UNKNOWN" ~ 7
), "Action\nTaken\n(2)"),
SERREAS = with_label(case_when(
AESDTH == "Y" ~ "1",
AESLIFE == "Y" ~ "2",
AESHOSP == "Y" ~ "3",
AESDISAB == "Y" ~ "4",
AESCONG == "Y" ~ "5",
AESMIE == "Y" ~ "6",
TRUE ~ " "
), "Reason\nClassified\nas Serious\n(3)"),
!!arm_var := with_label(.data[[arm_var]], "Treatment"),
AEDECOD = with_label(reformat(.data$AEDECOD, nocoding), "Adverse\nEvent MedDRA\nPreferred Term"),
ASTDY = with_label(.data$ASTDY, "Study\nDay of\nOnset"),
AESEV = with_label(.data$AESEV, "Most\nExtreme\nIntensity")
) %>%
select(all_of(c(
"ID", "ASR", arm_var, "AEDECOD", "TRTSDTM", "ASTDY", "ADURN",
"AESEV", "AEREL", "AEOUT", "AECONTRT", "ACTION", "SERREAS"
)))
adam_db
}
#' `AEL03` Listing 1 (Default) Listing of Serious Adverse Events.
#'
#' @include chevron_tlg-S4class.R
#' @export
#'
#' @examples
#' res <- run(ael03, syn_data)
ael03 <- chevron_l(
main = ael03_main,
preprocess = ael03_pre
)