-
Notifications
You must be signed in to change notification settings - Fork 7
/
init_aeExplorer.R
73 lines (62 loc) · 2.35 KB
/
init_aeExplorer.R
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
#' Initialize Settings for Adverse Event Explorer widget
#'
#' @param data `list` Named list of data frames that includes participant-level subject data (`dm`)
#' and event-level adverse event data (`aes`).
#' @param settings `list` Named list of settings.
#'
#' @return returns list with data and settings
#'
#' @import dplyr
#'
#' @export
init_aeExplorer <- function(data, settings) {
# creates flag if treatment_col is missing to trigger actions to avoid downstream JS errors and enable visualization of blinded(no treatment_col) data
missing_trt_flag <- (
is.null(settings[["dm"]][["treatment_col"]]) || # Check NULL first and evaluate logic left to right
trimws(settings[["dm"]][["treatment_col"]])==""
)
#if no treatment_col provided, create dummy treatment_col for group setting so that ae explorer JS doesn't bomb
if (missing_trt_flag) {
data$dm <- data$dm %>% dplyr::mutate(group_placeholder="All")
settings[["dm"]][["treatment_col"]] <- "group_placeholder"
}
# Merge treatment with adverse events.
dm_sub <- data$dm %>%
dplyr::select(
settings[["dm"]][["id_col"]],
settings[["dm"]][["treatment_col"]]
)
# left join to keep all rows in dm (even if there were no AEs)
anly <- dm_sub %>%
dplyr::left_join(
data$aes,
settings[['dm']][['id_col']]
)
ae_settings <- list()
ae_settings$variables <- list(
major = settings[['aes']][["bodsys_col"]],
minor = settings[['aes']][["term_col"]],
group = settings[["dm"]][["treatment_col"]],
id = settings[["dm"]][["id_col"]],
filters = list(),
details = list()
)
ae_settings$variableOptions <- list(
group = c(
settings[['dm']][["treatment_values--group1"]],
settings[['dm']][["treatment_values--group2"]]
)
)
ae_settings$defaults <- list(
placeholderFlag = list(
valueCol = settings[['aes']][["bodsys_col"]],
values = c("", NA, NULL)
)
)
#if no treatment_col provided, remove total column and group selection dropdown
if (missing_trt_flag){
ae_settings$defaults[["groupCols"]] = FALSE
ae_settings$defaults[["useVariableControls"]] = FALSE
}
return(list(data = anly, settings = ae_settings))
}