@@ -220,10 +220,10 @@ n_fun <- function(x){
220220# ' @export
221221# '
222222# ' @examples
223- havingIP <- function () {
224- if (requireNamespace(" curl" , quietly = TRUE )) {
225- return (isTRUE(tryCatch(curl :: has_internet (), error = function (... ) FALSE )))
226- }
223+ havingIP <- function () {
224+ if (requireNamespace(" curl" , quietly = TRUE )) {
225+ return (isTRUE(tryCatch(curl_has_internet (), error = function (... ) FALSE )))
226+ }
227227
228228 warning(" Package 'curl' is not available; assuming no internet connection." )
229229 FALSE
@@ -411,7 +411,7 @@ ggwithinstatsWithPriorNormalityCheck <- function(data, x, y, ylab, xlabels = NUL
411411 sufficient_sample <- length(subset_data ) > = 3
412412
413413 if (sufficient_sample && has_variation ) {
414- normality_test [[group ]] <- shapiro.test (subset_data )
414+ normality_test [[group ]] <- shapiro_test_wrapper (subset_data )
415415 } else {
416416 normality_test [[group ]] <- NULL
417417 if (! sufficient_sample ) {
@@ -441,7 +441,7 @@ ggwithinstatsWithPriorNormalityCheck <- function(data, x, y, ylab, xlabels = NUL
441441
442442
443443
444- plot <- ggstatsplot :: ggwithinstats (
444+ plot <- ggwithinstats_wrapper (
445445 data = data , x = !! x , y = !! y , type = type , centrality.type = " p" , ylab = ylab , xlab = " " , pairwise.comparisons = showPairwiseComp , var.equal = group_all_data_equal ,
446446 centrality.point.args = list (size = 5 , alpha = 0.5 , color = " darkblue" ), package = " pals" , palette = " glasbey" ,
447447 p.adjust.method = " holm" , ggplot.component = list (theme(text = element_text(size = 16 ), plot.subtitle = element_text(size = 17 , face = " bold" ))), ggsignif.args = list (textsize = 4 , tip_length = 0.01 )
@@ -499,7 +499,7 @@ ggbetweenstatsWithPriorNormalityCheck <- function(data, x, y, ylab, xlabels, sho
499499 sufficient_sample <- length(subset_data ) > = 3
500500
501501 if (sufficient_sample && has_variation ) {
502- normality_test [[group ]] <- shapiro.test (subset_data )
502+ normality_test [[group ]] <- shapiro_test_wrapper (subset_data )
503503 } else {
504504 normality_test [[group ]] <- NULL
505505 if (! sufficient_sample ) {
@@ -528,7 +528,7 @@ ggbetweenstatsWithPriorNormalityCheck <- function(data, x, y, ylab, xlabels, sho
528528 type <- ifelse(normallyDistributed , " p" , " np" )
529529
530530 # if one group_all_data_equal then we use the var.equal = TRUE, see here: https://github.com/IndrajeetPatil/ggstatsplot/issues/880
531- ggstatsplot :: ggbetweenstats (
531+ ggbetweenstats_wrapper (
532532 data = data , x = !! x , y = !! y , type = type , centrality.type = " p" , ylab = ylab , xlab = " " , pairwise.comparisons = showPairwiseComp , var.equal = group_all_data_equal ,
533533 centrality.point.args = list (size = 5 , alpha = 0.5 , color = " darkblue" ), package = " pals" , palette = " glasbey" , plot.type = plotType ,
534534 p.adjust.method = " holm" , ggplot.component = list (theme(text = element_text(size = 16 ), plot.subtitle = element_text(size = 17 , face = " bold" ))), ggsignif.args = list (textsize = 4 , tip_length = 0.01 )
@@ -580,7 +580,7 @@ ggbetweenstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlab
580580 sufficient_sample <- length(subset_data ) > = 3
581581
582582 if (sufficient_sample && has_variation ) {
583- normality_test [[group ]] <- shapiro.test (subset_data )
583+ normality_test [[group ]] <- shapiro_test_wrapper (subset_data )
584584 } else {
585585 normality_test [[group ]] <- NULL
586586 if (! sufficient_sample ) {
@@ -609,7 +609,7 @@ ggbetweenstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlab
609609
610610
611611 (df <-
612- pairwise_comparisons (data = data , x = !! x , y = !! y , type = type , p.adjust.method = " holm" ) %> %
612+ pairwise_comparisons_wrapper (data = data , x = !! x , y = !! y , type = type , p.adjust.method = " holm" ) %> %
613613 dplyr :: mutate(groups = purrr :: pmap(.l = list (group1 , group2 ), .f = c )) %> %
614614 dplyr :: arrange(group1 ) %> %
615615 dplyr :: mutate(asterisk_label = ifelse(`p.value` < 0.05 & `p.value` > 0.01 , " *" , ifelse(`p.value` < 0.01 & `p.value` > 0.001 , " **" , ifelse(`p.value` < 0.001 , " ***" , NA )))))
@@ -632,13 +632,13 @@ ggbetweenstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlab
632632 }
633633
634634
635- p <- ggstatsplot :: ggbetweenstats (
635+ p <- ggbetweenstats_wrapper (
636636 data = data , x = !! x , y = !! y , type = type , centrality.type = " p" , ylab = ylab , xlab = " " , pairwise.display = " none" , var.equal = group_all_data_equal ,
637637 centrality.point.args = list (size = 5 , alpha = 0.5 , color = " darkblue" ), package = " pals" , palette = " glasbey" , plot.type = plotType ,
638638 p.adjust.method = " holm" , ggplot.component = list (theme(text = element_text(size = 16 ), plot.subtitle = element_text(size = 17 , face = " bold" ))), ggsignif.args = list (textsize = 4 , tip_length = 0.01 )
639639 ) + scale_x_discrete(labels = xlabels )
640640
641- p + ggsignif :: geom_signif (
641+ p + geom_signif_wrapper (
642642 comparisons = df $ groups ,
643643 map_signif_level = TRUE ,
644644 annotations = df $ asterisk_label ,
@@ -677,7 +677,7 @@ ggwithinstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlabe
677677 sufficient_sample <- length(subset_data ) > = 3
678678
679679 if (sufficient_sample && has_variation ) {
680- normality_test [[group ]] <- shapiro.test (subset_data )
680+ normality_test [[group ]] <- shapiro_test_wrapper (subset_data )
681681 } else {
682682 normality_test [[group ]] <- NULL
683683 normality_assessable <- FALSE
@@ -700,7 +700,7 @@ ggwithinstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlabe
700700
701701
702702 (df <-
703- pairwise_comparisons (data = data , x = !! x , y = !! y , type = type , p.adjust.method = " holm" ) %> %
703+ pairwise_comparisons_wrapper (data = data , x = !! x , y = !! y , type = type , p.adjust.method = " holm" ) %> %
704704 dplyr :: mutate(groups = purrr :: pmap(.l = list (group1 , group2 ), .f = c )) %> %
705705 dplyr :: arrange(group1 ) %> %
706706 dplyr :: mutate(asterisk_label = ifelse(`p.value` < 0.05 & `p.value` > 0.01 , " *" , ifelse(`p.value` < 0.01 & `p.value` > 0.001 , " **" , ifelse(`p.value` < 0.001 , " ***" , NA )))))
@@ -723,13 +723,13 @@ ggwithinstatsWithPriorNormalityCheckAsterisk <- function(data, x, y, ylab, xlabe
723723 }
724724
725725
726- p <- ggstatsplot :: ggwithinstats (
726+ p <- ggwithinstats_wrapper (
727727 data = data , x = !! x , y = !! y , type = type , centrality.type = " p" , ylab = ylab , xlab = " " , pairwise.display = " none" ,
728728 centrality.point.args = list (size = 5 , alpha = 0.5 , color = " darkblue" ), package = " pals" , palette = " glasbey" , plot.type = plotType ,
729729 p.adjust.method = " holm" , ggplot.component = list (theme(text = element_text(size = 16 ), plot.subtitle = element_text(size = 17 , face = " bold" ))), ggsignif.args = list (textsize = 4 , tip_length = 0.01 )
730730 ) + scale_x_discrete(labels = xlabels )
731731
732- p + ggsignif :: geom_signif (
732+ p + geom_signif_wrapper (
733733 comparisons = df $ groups ,
734734 map_signif_level = TRUE ,
735735 annotations = df $ asterisk_label ,
@@ -1878,7 +1878,7 @@ reportggstatsplot <- function(p, iv = "independent", dv = "Testdependentvariable
18781878 not_empty(dv )
18791879 not_empty(iv )
18801880
1881- stats <- extract_stats (p )$ subtitle_data
1881+ stats <- extract_stats_wrapper (p )$ subtitle_data
18821882 resultString <- " "
18831883
18841884 effectSize <- round(stats $ estimate , digits = 2 )
@@ -2687,7 +2687,7 @@ reportggstatsplotPostHoc <- function(data, p, iv = "testiv", dv = "testdv", labe
26872687 not_empty(dv )
26882688
26892689 # Extract stats from the ggstatsplot object
2690- stats <- extract_stats (p )$ pairwise_comparisons_data
2690+ stats <- extract_stats_wrapper (p )$ pairwise_comparisons_data
26912691
26922692 if (! any(stats $ p.value < 0.05 , na.rm = TRUE )) {
26932693 cat(paste0(" A post-hoc test found no significant differences for " , dv , " . " ))
@@ -2757,3 +2757,12 @@ reportggstatsplotPostHoc <- function(data, p, iv = "testiv", dv = "testdv", labe
27572757
27582758
27592759
2760+ # Helper wrappers around external functions so they can be mocked in tests
2761+ curl_has_internet <- function (... ) curl :: has_internet(... )
2762+ ggwithinstats_wrapper <- function (... ) ggstatsplot :: ggwithinstats(... )
2763+ ggbetweenstats_wrapper <- function (... ) ggstatsplot :: ggbetweenstats(... )
2764+ pairwise_comparisons_wrapper <- function (... ) ggstatsplot :: pairwise_comparisons(... )
2765+ geom_signif_wrapper <- function (... ) ggsignif :: geom_signif(... )
2766+ shapiro_test_wrapper <- function (... ) stats :: shapiro.test(... )
2767+ extract_stats_wrapper <- function (... ) ggstatsplot :: extract_stats(... )
2768+
0 commit comments