@@ -38,7 +38,7 @@ merge_with_no_duplicate_cols <- function(a, b, by) merge(a, b[c(by, setdiff(name
3838# ' @keywords internal
3939# '
4040robust_ymd <- function (data , round_up = FALSE ) {
41- # NOTE(miguel):
41+ # NOTE(miguel):
4242 # `dv.papo` used to rely on `lubridate` for date parsing.
4343 # We dropped that library because we didn't need any of its many advanced features.
4444 # Instead, we wrote this function to parse the only format we cared about ('yyyy-mm-dd'),
@@ -81,3 +81,138 @@ robust_ymd <- function(data, round_up = FALSE) {
8181
8282 return (data )
8383}
84+
85+ # ' Get missing mandatory plot list items
86+ # '
87+ # ' @param plots `[list(1+)]` named list containing plot configuration.
88+ # ' @return `[list(1+)]`
89+ # '
90+ get_missing_plot_params <- function (plots ) {
91+
92+ m <- CONST $ plot_mandatory_params # let 'm' denote mandatory params
93+ v <- CONST $ plot_default_vals # let 'v' denote default vals
94+
95+
96+ # 1. check timeline_info
97+ if (! rlang :: has_name(plots , " timeline_info" )) {
98+ plots [[" timeline_info" ]] <- v [[" timeline_info" ]]
99+ } else {
100+ for (item in m [[" timeline_info" ]]) {
101+ if (! rlang :: has_name(plots [[" timeline_info" ]], item )) {
102+ plots [[" timeline_info" ]][[item ]] <- v [[" timeline_info" ]][[item ]]
103+ }
104+ }
105+ }
106+
107+ # 2. check vline_vars
108+ if (! rlang :: has_name(plots , " vline_vars" )) {
109+ plots [[" vline_vars" ]] <- v [[" vline_vars" ]]
110+ }
111+
112+ # 3. check plots
113+
114+ plot_type_info <- list (
115+ range_plots <- list (
116+ ae = list (regexp = " adverse events" , v_plot_name = " Adverse Events Plot" ),
117+ cm = list (regexp = " concomitant medication" , v_plot_name = " Concomitant Medication Plot" )
118+ ),
119+ value_plots = list (
120+ lab = list (regexp = " ^lab plot" , dv_plot_name = " Lab plot" ),
121+ vital = list (regexp = " vital sign" , v_plot_name = " Vital Sign Plot" )
122+ )
123+ )
124+
125+ if (! rlang :: has_name(plots , " range_plots" )) {
126+ plots [[" range_plots" ]] <- v [[" range_plots" ]]
127+ } else {
128+ # i. check all range_plots
129+ # for (rp in )
130+ if (any(grepl(" adverse event" , names(plots [[" range_plots" ]]), ignore.case = TRUE ))) {
131+ plot_name <- grep(
132+ " adverse event" , names(plots [[" range_plots" ]]), ignore.case = TRUE , value = TRUE
133+ )
134+ for (i in plot_name ) {
135+ for (j in names(range_plot_params )) {
136+ if (j %in% c(" vars" )) {
137+ for (var_col in m [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]]) {
138+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]][[j ]], var_col )) {
139+ plots [[" range_plots" ]][[i ]][[j ]][[var_col ]] <-
140+ v [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]][[var_col ]]
141+ }
142+ }
143+ } else {
144+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]], j )) {
145+ plots [[" range_plots" ]][[i ]][[j ]] <- v [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]]
146+ }
147+ }
148+ }
149+ }
150+ }
151+ }
152+
153+ if (! rlang :: has_name(plots , " range_plots" )) {
154+ plots [[" range_plots" ]] <- v [[" range_plots" ]]
155+ } else {
156+ range_plot_params <- m [[" range_plots" ]][[1 ]] # params are the same for AE, CM plots
157+
158+ # i. Adverse Event plot checks
159+ if (any(grepl(" adverse event" , names(plots [[" range_plots" ]]), ignore.case = TRUE ))) {
160+ plot_name <- grep(
161+ " adverse event" , names(plots [[" range_plots" ]]), ignore.case = TRUE , value = TRUE
162+ )
163+ for (i in plot_name ) {
164+ for (j in names(range_plot_params )) {
165+ if (j %in% c(" vars" )) {
166+ for (var_col in m [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]]) {
167+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]][[j ]], var_col )) {
168+ plots [[" range_plots" ]][[i ]][[j ]][[var_col ]] <-
169+ v [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]][[var_col ]]
170+ }
171+ }
172+ } else {
173+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]], j )) {
174+ plots [[" range_plots" ]][[i ]][[j ]] <- v [[" range_plots" ]][[" Adverse Events Plot" ]][[j ]]
175+ }
176+ }
177+ }
178+ }
179+ }
180+
181+ # ii. Concomitant Medication Plot checks
182+ if (any(grepl(" concomitant medication" , names(plots [[" range_plots" ]]), ignore.case = TRUE ))) {
183+ plot_name <- grep(
184+ " concomitant medication" , names(plots [[" range_plots" ]]), ignore.case = TRUE , value = TRUE
185+ )
186+ for (i in plot_name ) {
187+ for (j in names(range_plot_params )) {
188+ if (j %in% c(" vars" )) {
189+ for (var_col in m [[" range_plots" ]][[" Concomitant Medication Plot" ]][[j ]]) {
190+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]][[j ]], var_col )) {
191+ plots [[" range_plots" ]][[i ]][[j ]][[var_col ]] <-
192+ v [[" range_plots" ]][[" Concomitant Medication Plot" ]][[j ]][[var_col ]]
193+ }
194+ }
195+ } else {
196+ if (! rlang :: has_name(plots [[" range_plots" ]][[i ]], j )) {
197+ plots [[" range_plots" ]][[i ]][[j ]] <- v [[" range_plots" ]][[" Concomitant Medication Plot" ]][[j ]]
198+ }
199+ }
200+ }
201+ }
202+ }
203+ }
204+
205+
206+ # check value_plots
207+
208+
209+ }
210+ # ' Apply default vals to plot list.
211+ # '
212+ # ' @param plots `[list(1+)]` named list containing plot configuration.
213+ # '
214+ # ' @return `[list(1+)]`
215+ # ' @keywords internal
216+ apply_plot_default_vals <- function (plots ) {
217+
218+ }
0 commit comments