5050# ' library(teal.modules.general)
5151# ' interactive <- function() TRUE
5252# ' {{ next_example }}
53- # ' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
53+ # ' @examples
5454# ' # general example data
5555# ' data <- teal_data()
5656# ' data <- within(data, {
8484# ' library(teal.modules.general)
8585# ' interactive <- function() TRUE
8686# ' {{ next_example }}
87- # ' @examplesIf require("gridExtra", quietly = TRUE) && require("rlang", quietly = TRUE)
87+ # ' @examples
8888# ' # CDISC example data
8989# ' data <- teal_data()
9090# ' data <- within(data, {
@@ -121,14 +121,6 @@ tm_missing_data <- function(label = "Missing data",
121121 decorators = NULL ) {
122122 message(" Initializing tm_missing_data" )
123123
124- # Requires Suggested packages
125- if (! requireNamespace(" gridExtra" , quietly = TRUE )) {
126- stop(" Cannot load gridExtra - please install the package or restart your session." )
127- }
128- if (! requireNamespace(" rlang" , quietly = TRUE )) {
129- stop(" Cannot load rlang - please install the package or restart your session." )
130- }
131-
132124 # Normalize the parameters
133125 if (inherits(ggplot2_args , " ggplot2_args" )) ggplot2_args <- list (default = ggplot2_args )
134126
@@ -1175,6 +1167,13 @@ srv_missing_data <- function(id,
11751167 ggtheme = input $ ggtheme
11761168 )
11771169
1170+ # Unlikely that `rlang` is not available, new hashing may be expensive
1171+ hashing_function <- if (requireNamespace(" rlang" , quietly = TRUE )) {
1172+ quote(rlang :: hash )
1173+ } else {
1174+ function (x ) paste(as.integer(x ), collapse = " " )
1175+ }
1176+
11781177 teal.code :: eval_code(
11791178 common_code_q(),
11801179 substitute(
@@ -1189,41 +1188,44 @@ srv_missing_data <- function(id,
11891188 )
11901189 ) %> %
11911190 teal.code :: eval_code(
1192- quote({
1193- summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1194- dplyr :: group_by_at(parent_keys ) %> %
1195- dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1196- dplyr :: ungroup() %> %
1197- dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1198- dplyr :: summarise_all(anyNA ) %> %
1199- dplyr :: ungroup()
1200-
1201- # order subjects by decreasing number of missing and then by
1202- # missingness pattern (defined using sha1)
1203- order_subjects <- summary_plot_patients %> %
1204- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1205- dplyr :: transmute(
1206- id = dplyr :: row_number(),
1207- number_NA = apply(. , 1 , sum ),
1208- sha = apply(. , 1 , rlang :: hash )
1209- ) %> %
1210- dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1211- getElement(name = " id" )
1212-
1213- # order columns by decreasing percent of missing values
1214- ordered_columns <- summary_plot_patients %> %
1215- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1216- dplyr :: summarise(
1217- column = create_cols_labels(colnames(. )),
1218- na_count = apply(. , MARGIN = 2 , FUN = sum ),
1219- na_percent = na_count / nrow(. ) * 100
1220- ) %> %
1221- dplyr :: arrange(na_percent , dplyr :: desc(column ))
1222-
1223- summary_plot_patients <- summary_plot_patients %> %
1224- tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1225- dplyr :: mutate(col = create_cols_labels(col ))
1226- })
1191+ substitute(
1192+ expr = {
1193+ summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1194+ dplyr :: group_by_at(parent_keys ) %> %
1195+ dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1196+ dplyr :: ungroup() %> %
1197+ dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1198+ dplyr :: summarise_all(anyNA ) %> %
1199+ dplyr :: ungroup()
1200+
1201+ # order subjects by decreasing number of missing and then by
1202+ # missingness pattern (defined using sha1)
1203+ order_subjects <- summary_plot_patients %> %
1204+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1205+ dplyr :: transmute(
1206+ id = dplyr :: row_number(),
1207+ number_NA = apply(. , 1 , sum ),
1208+ sha = apply(. , 1 , hashing_function )
1209+ ) %> %
1210+ dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1211+ getElement(name = " id" )
1212+
1213+ # order columns by decreasing percent of missing values
1214+ ordered_columns <- summary_plot_patients %> %
1215+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1216+ dplyr :: summarise(
1217+ column = create_cols_labels(colnames(. )),
1218+ na_count = apply(. , MARGIN = 2 , FUN = sum ),
1219+ na_percent = na_count / nrow(. ) * 100
1220+ ) %> %
1221+ dplyr :: arrange(na_percent , dplyr :: desc(column ))
1222+
1223+ summary_plot_patients <- summary_plot_patients %> %
1224+ tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1225+ dplyr :: mutate(col = create_cols_labels(col ))
1226+ },
1227+ env = list (hashing_function = hashing_function )
1228+ )
12271229 ) %> %
12281230 teal.code :: eval_code(
12291231 substitute(
0 commit comments