@@ -91,14 +91,6 @@ tm_missing_data <- function(label = "Missing data",
9191 post_output = NULL ) {
9292 message(" Initializing tm_missing_data" )
9393
94- # Requires Suggested packages
95- if (! requireNamespace(" gridExtra" , quietly = TRUE )) {
96- stop(" Cannot load gridExtra - please install the package or restart your session." )
97- }
98- if (! requireNamespace(" rlang" , quietly = TRUE )) {
99- stop(" Cannot load rlang - please install the package or restart your session." )
100- }
101-
10294 # Normalize the parameters
10395 if (inherits(ggplot2_args , " ggplot2_args" )) ggplot2_args <- list (default = ggplot2_args )
10496
@@ -1135,6 +1127,13 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11351127 ggtheme = input $ ggtheme
11361128 )
11371129
1130+ # Unlikely that `rlang` is not available, new hashing may be expensive
1131+ hashing_function <- if (requireNamespace(" rlang" , quietly = TRUE )) {
1132+ quote(rlang :: hash )
1133+ } else {
1134+ function (x ) paste(as.integer(x ), collapse = " " )
1135+ }
1136+
11381137 teal.code :: eval_code(
11391138 common_code_q(),
11401139 substitute(
@@ -1149,41 +1148,44 @@ srv_missing_data <- function(id, data, reporter, filter_panel_api, dataname, par
11491148 )
11501149 ) %> %
11511150 teal.code :: eval_code(
1152- quote({
1153- summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1154- dplyr :: group_by_at(parent_keys ) %> %
1155- dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1156- dplyr :: ungroup() %> %
1157- dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1158- dplyr :: summarise_all(anyNA ) %> %
1159- dplyr :: ungroup()
1160-
1161- # order subjects by decreasing number of missing and then by
1162- # missingness pattern (defined using sha1)
1163- order_subjects <- summary_plot_patients %> %
1164- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1165- dplyr :: transmute(
1166- id = dplyr :: row_number(),
1167- number_NA = apply(. , 1 , sum ),
1168- sha = apply(. , 1 , rlang :: hash )
1169- ) %> %
1170- dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1171- getElement(name = " id" )
1172-
1173- # order columns by decreasing percent of missing values
1174- ordered_columns <- summary_plot_patients %> %
1175- dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1176- dplyr :: summarise(
1177- column = create_cols_labels(colnames(. )),
1178- na_count = apply(. , MARGIN = 2 , FUN = sum ),
1179- na_percent = na_count / nrow(. ) * 100
1180- ) %> %
1181- dplyr :: arrange(na_percent , dplyr :: desc(column ))
1182-
1183- summary_plot_patients <- summary_plot_patients %> %
1184- tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1185- dplyr :: mutate(col = create_cols_labels(col ))
1186- })
1151+ substitute(
1152+ expr = {
1153+ summary_plot_patients <- ANL [, c(parent_keys , analysis_vars )] %> %
1154+ dplyr :: group_by_at(parent_keys ) %> %
1155+ dplyr :: mutate(id = dplyr :: cur_group_id()) %> %
1156+ dplyr :: ungroup() %> %
1157+ dplyr :: group_by_at(c(parent_keys , " id" )) %> %
1158+ dplyr :: summarise_all(anyNA ) %> %
1159+ dplyr :: ungroup()
1160+
1161+ # order subjects by decreasing number of missing and then by
1162+ # missingness pattern (defined using sha1)
1163+ order_subjects <- summary_plot_patients %> %
1164+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1165+ dplyr :: transmute(
1166+ id = dplyr :: row_number(),
1167+ number_NA = apply(. , 1 , sum ),
1168+ sha = apply(. , 1 , hashing_function )
1169+ ) %> %
1170+ dplyr :: arrange(dplyr :: desc(number_NA ), sha ) %> %
1171+ getElement(name = " id" )
1172+
1173+ # order columns by decreasing percent of missing values
1174+ ordered_columns <- summary_plot_patients %> %
1175+ dplyr :: select(- " id" , - dplyr :: all_of(parent_keys )) %> %
1176+ dplyr :: summarise(
1177+ column = create_cols_labels(colnames(. )),
1178+ na_count = apply(. , MARGIN = 2 , FUN = sum ),
1179+ na_percent = na_count / nrow(. ) * 100
1180+ ) %> %
1181+ dplyr :: arrange(na_percent , dplyr :: desc(column ))
1182+
1183+ summary_plot_patients <- summary_plot_patients %> %
1184+ tidyr :: gather(" col" , " isna" , - " id" , - dplyr :: all_of(parent_keys )) %> %
1185+ dplyr :: mutate(col = create_cols_labels(col ))
1186+ },
1187+ env = list (hashing_function = hashing_function )
1188+ )
11871189 ) %> %
11881190 teal.code :: eval_code(
11891191 substitute(
0 commit comments