Skip to content

Commit cb2de81

Browse files
committed
Restored main version reversing changes pertaining to DEVR-3528 about issue86
1 parent acf5427 commit cb2de81

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

R/react_base_char.R

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -67,36 +67,13 @@ react_base_char <- function(
6767
# ----------------------------------------- #
6868
# total setting #
6969
# ----------------------------------------- #
70-
70+
7171
if (display_total == TRUE) {
7272
display_sl <- c("n", "prop", "total")
7373
} else {
7474
display_sl <- c("n", "prop")
7575
}
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+
10077
# ----------------------------------------- #
10178
# prepare the baseline char table numbers #
10279
# ----------------------------------------- #
@@ -107,10 +84,10 @@ react_base_char <- function(
10784
parameter = sl_parameter
10885
) |>
10986
format_base_char(display_col = display_sl, digits_prop = 2)
110-
87+
11188
tbl_sl <- x_sl$tbl
11289
tbl_sl$var_label[tbl_sl$name == "Participants in population"] <- "Participants in population"
113-
90+
11491
# ----------------------------------------- #
11592
# prepare the AE subgroup table numbers #
11693
# ----------------------------------------- #
@@ -125,14 +102,14 @@ react_base_char <- function(
125102
}
126103
ae_subgrp_label <- c(ae_subgrp_label, metalite::collect_adam_mapping(metadata_sl, x_subgrp)$label)
127104
}
128-
105+
129106
# get the AE subgroup tables
130107
tbl_ae <- list()
131108
group_ae <- list()
132-
109+
133110
# define the space character
134111
space_char <- "\u2003\u2003"
135-
112+
136113
for (y_subgrp in ae_subgrp_var) {
137114
sl_pop_subgrp <- metalite::collect_population_record(metadata_sl, population, var = y_subgrp)[[y_subgrp]]
138115
ae_pop_subgrp <- metalite::collect_population_record(metadata_ae, population, var = y_subgrp)[[y_subgrp]]
@@ -150,7 +127,7 @@ react_base_char <- function(
150127
"ae: ", paste0(ae_pop_subgrp, collapse = ", ")
151128
))
152129
}
153-
130+
154131
tbl_ae_temp <- metalite.ae::prepare_ae_specific_subgroup(
155132
metadata_ae,
156133
population = population,
@@ -160,7 +137,7 @@ react_base_char <- function(
160137
display_subgroup_total = FALSE # total display for subgroup is not needed
161138
) |>
162139
metalite.ae::format_ae_specific_subgroup()
163-
140+
164141
# modify the name elements in tbl_ae_temp$tbl: add spaces in name other than the value of "Participants in population"
165142
tbl_ae_temp$tbl$name <- sapply(tbl_ae_temp$tbl$name, function(x) {
166143
if (trimws(x) == "Participants in population") {
@@ -170,7 +147,7 @@ react_base_char <- function(
170147
return(paste0(space_char, x)) # Prepend spaces
171148
}
172149
})
173-
150+
174151
tbl_ae <- c(tbl_ae, list(tbl_ae_temp$tbl))
175152
# get group labels for AE analysis
176153
group_ae <- c(group_ae, list(tbl_ae_temp$group))
@@ -181,7 +158,7 @@ react_base_char <- function(
181158
# group_ae <- c(group_ae, list(tbl_ae_temp$group[!(tbl_ae_temp$group %in% "total")]))
182159
# }
183160
}
184-
161+
185162
# get the AE specific
186163
ae_specific_outdata <- metalite.ae::prepare_ae_specific(
187164
metadata_ae,
@@ -190,7 +167,7 @@ react_base_char <- function(
190167
parameter = ae_specific
191168
) |>
192169
metalite.ae::format_ae_specific(display = display_sl)
193-
170+
194171
# modify the name elements in ae_specific_outdata$tbl$name: add spaces in name other than the value of "Participants in population"
195172
ae_specific_outdata$tbl$name <- sapply(ae_specific_outdata$tbl$name, function(x) {
196173
if (trimws(x) == "Participants in population" || is.na(x)) {
@@ -199,15 +176,15 @@ react_base_char <- function(
199176
return(paste0(space_char, x)) # Prepend spaces
200177
}
201178
})
202-
179+
203180
# Define Column and Column Group for AE specific
204181
col_defs_ae <- list()
205182
col_group_defs_ae <- list()
206183
col_defs_ae[["name"]] <- reactable::colDef(name = " ")
207184
for (i in 1:length(ae_specific_outdata$group)) {
208185
col_defs_ae[[paste0("n_", i)]] <- reactable::colDef(name = "n")
209186
col_defs_ae[[paste0("prop_", i)]] <- reactable::colDef(name = "(%)")
210-
187+
211188
col_group_defs_ae <- append(
212189
col_group_defs_ae,
213190
list(reactable::colGroup(
@@ -216,8 +193,8 @@ react_base_char <- function(
216193
))
217194
)
218195
}
219-
220-
196+
197+
221198
# ----------------------------------------- #
222199
# build interactive baseline char table #
223200
# ----------------------------------------- #
@@ -232,7 +209,7 @@ react_base_char <- function(
232209
col_defs[[sl_name]] <- reactable::colDef(name = " ")
233210
}
234211
}
235-
212+
236213
# Define Column Group
237214
col_group_defs <- list()
238215
for (i in 1:length(x_sl$group_label)) {
@@ -254,7 +231,7 @@ react_base_char <- function(
254231
))
255232
)
256233
}
257-
234+
258235
reactable::reactable(
259236
tbl_sl,
260237
groupBy = "var_label",
@@ -263,12 +240,12 @@ react_base_char <- function(
263240
columnGroups = col_group_defs,
264241
details = function(index) {
265242
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])
268245
) {
269246
# get the index of the AE subgroup variable by the index in the baseline char table
270247
idx_ae_subgroup <- which(tbl_sl$var_label[index] == ae_subgrp_label)
271-
248+
272249
# get the table for this AE subgroup variable
273250
tbl_ae[[idx_ae_subgroup]] |>
274251
react_subgroup_table(
@@ -285,4 +262,4 @@ react_base_char <- function(
285262
}
286263
}
287264
)
288-
}
265+
}

0 commit comments

Comments
 (0)