@@ -67,36 +67,13 @@ react_base_char <- function(
67
67
# ----------------------------------------- #
68
68
# total setting #
69
69
# ----------------------------------------- #
70
-
70
+
71
71
if (display_total == TRUE ) {
72
72
display_sl <- c(" n" , " prop" , " total" )
73
73
} else {
74
74
display_sl <- c(" n" , " prop" )
75
75
}
76
-
77
- # ---------------------------------------------- #
78
- # ensure capitalizing the first letter of RACE #
79
- # ---------------------------------------------- #
80
-
81
- # function to capitalize the first letter of each word
82
- capitalize_words <- function (x ) {
83
- sapply(x , function (word ) {
84
- paste0(toupper(substr(word , 1 , 1 )), tolower(substr(word , 2 , nchar(word ))))
85
- })
86
- }
87
-
88
- # 1) In data_population: extract the RACE values as a character vector
89
- race_values_pop <- metadata_sl [[" data_population" ]]$ RACE # Use $ to get a vector
90
-
91
- # Capitalize the race values
92
- metadata_sl [[" data_population" ]]$ RACE <- capitalize_words(race_values_pop ) # Assign back as a vector
93
-
94
- # 2) In data_observation: extract the RACE values as a character vector
95
- race_values_obs <- metadata_sl [[" data_observation" ]]$ RACE # Use $ to get a vector
96
-
97
- # Capitalize the race values
98
- metadata_sl [[" data_observation" ]]$ RACE <- capitalize_words(race_values_obs ) # Assign back as a vector
99
-
76
+
100
77
# ----------------------------------------- #
101
78
# prepare the baseline char table numbers #
102
79
# ----------------------------------------- #
@@ -107,10 +84,10 @@ react_base_char <- function(
107
84
parameter = sl_parameter
108
85
) | >
109
86
format_base_char(display_col = display_sl , digits_prop = 2 )
110
-
87
+
111
88
tbl_sl <- x_sl $ tbl
112
89
tbl_sl $ var_label [tbl_sl $ name == " Participants in population" ] <- " Participants in population"
113
-
90
+
114
91
# ----------------------------------------- #
115
92
# prepare the AE subgroup table numbers #
116
93
# ----------------------------------------- #
@@ -125,14 +102,14 @@ react_base_char <- function(
125
102
}
126
103
ae_subgrp_label <- c(ae_subgrp_label , metalite :: collect_adam_mapping(metadata_sl , x_subgrp )$ label )
127
104
}
128
-
105
+
129
106
# get the AE subgroup tables
130
107
tbl_ae <- list ()
131
108
group_ae <- list ()
132
-
109
+
133
110
# define the space character
134
111
space_char <- " \u 2003\u 2003"
135
-
112
+
136
113
for (y_subgrp in ae_subgrp_var ) {
137
114
sl_pop_subgrp <- metalite :: collect_population_record(metadata_sl , population , var = y_subgrp )[[y_subgrp ]]
138
115
ae_pop_subgrp <- metalite :: collect_population_record(metadata_ae , population , var = y_subgrp )[[y_subgrp ]]
@@ -150,7 +127,7 @@ react_base_char <- function(
150
127
" ae: " , paste0(ae_pop_subgrp , collapse = " , " )
151
128
))
152
129
}
153
-
130
+
154
131
tbl_ae_temp <- metalite.ae :: prepare_ae_specific_subgroup(
155
132
metadata_ae ,
156
133
population = population ,
@@ -160,7 +137,7 @@ react_base_char <- function(
160
137
display_subgroup_total = FALSE # total display for subgroup is not needed
161
138
) | >
162
139
metalite.ae :: format_ae_specific_subgroup()
163
-
140
+
164
141
# modify the name elements in tbl_ae_temp$tbl: add spaces in name other than the value of "Participants in population"
165
142
tbl_ae_temp $ tbl $ name <- sapply(tbl_ae_temp $ tbl $ name , function (x ) {
166
143
if (trimws(x ) == " Participants in population" ) {
@@ -170,7 +147,7 @@ react_base_char <- function(
170
147
return (paste0(space_char , x )) # Prepend spaces
171
148
}
172
149
})
173
-
150
+
174
151
tbl_ae <- c(tbl_ae , list (tbl_ae_temp $ tbl ))
175
152
# get group labels for AE analysis
176
153
group_ae <- c(group_ae , list (tbl_ae_temp $ group ))
@@ -181,7 +158,7 @@ react_base_char <- function(
181
158
# group_ae <- c(group_ae, list(tbl_ae_temp$group[!(tbl_ae_temp$group %in% "total")]))
182
159
# }
183
160
}
184
-
161
+
185
162
# get the AE specific
186
163
ae_specific_outdata <- metalite.ae :: prepare_ae_specific(
187
164
metadata_ae ,
@@ -190,7 +167,7 @@ react_base_char <- function(
190
167
parameter = ae_specific
191
168
) | >
192
169
metalite.ae :: format_ae_specific(display = display_sl )
193
-
170
+
194
171
# modify the name elements in ae_specific_outdata$tbl$name: add spaces in name other than the value of "Participants in population"
195
172
ae_specific_outdata $ tbl $ name <- sapply(ae_specific_outdata $ tbl $ name , function (x ) {
196
173
if (trimws(x ) == " Participants in population" || is.na(x )) {
@@ -199,15 +176,15 @@ react_base_char <- function(
199
176
return (paste0(space_char , x )) # Prepend spaces
200
177
}
201
178
})
202
-
179
+
203
180
# Define Column and Column Group for AE specific
204
181
col_defs_ae <- list ()
205
182
col_group_defs_ae <- list ()
206
183
col_defs_ae [[" name" ]] <- reactable :: colDef(name = " " )
207
184
for (i in 1 : length(ae_specific_outdata $ group )) {
208
185
col_defs_ae [[paste0(" n_" , i )]] <- reactable :: colDef(name = " n" )
209
186
col_defs_ae [[paste0(" prop_" , i )]] <- reactable :: colDef(name = " (%)" )
210
-
187
+
211
188
col_group_defs_ae <- append(
212
189
col_group_defs_ae ,
213
190
list (reactable :: colGroup(
@@ -216,8 +193,8 @@ react_base_char <- function(
216
193
))
217
194
)
218
195
}
219
-
220
-
196
+
197
+
221
198
# ----------------------------------------- #
222
199
# build interactive baseline char table #
223
200
# ----------------------------------------- #
@@ -232,7 +209,7 @@ react_base_char <- function(
232
209
col_defs [[sl_name ]] <- reactable :: colDef(name = " " )
233
210
}
234
211
}
235
-
212
+
236
213
# Define Column Group
237
214
col_group_defs <- list ()
238
215
for (i in 1 : length(x_sl $ group_label )) {
@@ -254,7 +231,7 @@ react_base_char <- function(
254
231
))
255
232
)
256
233
}
257
-
234
+
258
235
reactable :: reactable(
259
236
tbl_sl ,
260
237
groupBy = " var_label" ,
@@ -263,12 +240,12 @@ react_base_char <- function(
263
240
columnGroups = col_group_defs ,
264
241
details = function (index ) {
265
242
if (index > 1 &
266
- ! (tolower(tbl_sl $ name [index ]) %in% c(" mean" , " sd" , " median" , " min" , " max" , " se" , " q1" , " q3" , " q1 to q3" , " range" )) &
267
- tbl_sl $ var_label [index ] %in% ae_subgrp_label & ! is.na(tbl_sl $ name [index ])
243
+ ! (tolower(tbl_sl $ name [index ]) %in% c(" mean" , " sd" , " median" , " min" , " max" , " se" , " q1" , " q3" , " q1 to q3" , " range" )) &
244
+ tbl_sl $ var_label [index ] %in% ae_subgrp_label & ! is.na(tbl_sl $ name [index ])
268
245
) {
269
246
# get the index of the AE subgroup variable by the index in the baseline char table
270
247
idx_ae_subgroup <- which(tbl_sl $ var_label [index ] == ae_subgrp_label )
271
-
248
+
272
249
# get the table for this AE subgroup variable
273
250
tbl_ae [[idx_ae_subgroup ]] | >
274
251
react_subgroup_table(
@@ -285,4 +262,4 @@ react_base_char <- function(
285
262
}
286
263
}
287
264
)
288
- }
265
+ }
0 commit comments