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, {
@@ -120,14 +120,6 @@ tm_missing_data <- function(label = "Missing data",
120120 decorators = NULL ) {
121121 message(" Initializing tm_missing_data" )
122122
123- # Requires Suggested packages
124- if (! requireNamespace(" gridExtra" , quietly = TRUE )) {
125- stop(" Cannot load gridExtra - please install the package or restart your session." )
126- }
127- if (! requireNamespace(" rlang" , quietly = TRUE )) {
128- stop(" Cannot load rlang - please install the package or restart your session." )
129- }
130-
131123 # Normalize the parameters
132124 if (inherits(ggplot2_args , " ggplot2_args" )) ggplot2_args <- list (default = ggplot2_args )
133125
@@ -1173,6 +1165,13 @@ srv_missing_data <- function(id,
11731165 ggtheme = input $ ggtheme
11741166 )
11751167
1168+ # Unlikely that `rlang` is not available, new hashing may be expensive
1169+ hashing_function <- if (requireNamespace(" rlang" , quietly = TRUE )) {
1170+ quote(rlang :: hash )
1171+ } else {
1172+ function (x ) paste(as.integer(x ), collapse = " " )
1173+ }
1174+
11761175 teal.code :: eval_code(
11771176 common_code_q(),
11781177 substitute(
@@ -1187,41 +1186,44 @@ srv_missing_data <- function(id,
11871186 )
11881187 ) %> %
11891188 teal.code :: eval_code(
1190- quote({
1191- summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1192- dplyr :: group_by_at(parent_keys ) %> %
1193- dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1194- dplyr :: ungroup() %> %
1195- dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1196- dplyr :: summarise_all(anyNA ) %> %
1197- dplyr :: ungroup()
1198-
1199- # order subjects by decreasing number of missing and then by
1200- # missingness pattern (defined using sha1)
1201- order_subjects <- summary_plot_patients %> %
1202- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1203- dplyr :: transmute(
1204- id = dplyr :: row_number(),
1205- number_NA = apply(. , 1 , sum ),
1206- sha = apply(. , 1 , rlang :: hash )
1207- ) %> %
1208- dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1209- getElement(name = " id" )
1210-
1211- # order columns by decreasing percent of missing values
1212- ordered_columns <- summary_plot_patients %> %
1213- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1214- dplyr :: summarise(
1215- column = create_cols_labels(colnames(. )),
1216- na_count = apply(. , MARGIN = 2 , FUN = sum ),
1217- na_percent = na_count / nrow(. ) * 100
1218- ) %> %
1219- dplyr :: arrange(na_percent , dplyr :: desc(column ))
1220-
1221- summary_plot_patients <- summary_plot_patients %> %
1222- tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1223- dplyr :: mutate(col = create_cols_labels(col ))
1224- })
1189+ substitute(
1190+ expr = {
1191+ summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1192+ dplyr :: group_by_at(parent_keys ) %> %
1193+ dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1194+ dplyr :: ungroup() %> %
1195+ dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1196+ dplyr :: summarise_all(anyNA ) %> %
1197+ dplyr :: ungroup()
1198+
1199+ # order subjects by decreasing number of missing and then by
1200+ # missingness pattern (defined using sha1)
1201+ order_subjects <- summary_plot_patients %> %
1202+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1203+ dplyr :: transmute(
1204+ id = dplyr :: row_number(),
1205+ number_NA = apply(. , 1 , sum ),
1206+ sha = apply(. , 1 , hashing_function )
1207+ ) %> %
1208+ dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1209+ getElement(name = " id" )
1210+
1211+ # order columns by decreasing percent of missing values
1212+ ordered_columns <- summary_plot_patients %> %
1213+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1214+ dplyr :: summarise(
1215+ column = create_cols_labels(colnames(. )),
1216+ na_count = apply(. , MARGIN = 2 , FUN = sum ),
1217+ na_percent = na_count / nrow(. ) * 100
1218+ ) %> %
1219+ dplyr :: arrange(na_percent , dplyr :: desc(column ))
1220+
1221+ summary_plot_patients <- summary_plot_patients %> %
1222+ tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1223+ dplyr :: mutate(col = create_cols_labels(col ))
1224+ },
1225+ env = list (hashing_function = hashing_function )
1226+ )
12251227 ) %> %
12261228 teal.code :: eval_code(
12271229 substitute(
0 commit comments