diff --git a/DESCRIPTION b/DESCRIPTION index 4e7d4fe..f9b0085 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -49,7 +49,7 @@ Imports: dplyr, effsize, ggbeeswarm, - ggplot2 (>= 3.5.1), + ggplot2 (>= 3.5.2), ggsci, grid, magrittr, diff --git a/R/001_api.R b/R/001_api.R index 0fd1b28..f6a08d4 100644 --- a/R/001_api.R +++ b/R/001_api.R @@ -301,6 +301,7 @@ load <- function( #' @noRd #' #' @param x a dabest object, set as x to tally with method signature for print functions +#' @param print_greet_end a boolean value for printing with greeting/ending. #' @param ... S3 signature for generic plot function. #' #' @return A summary of the experimental designs. @@ -319,29 +320,35 @@ load <- function( #' print(dabest_obj) #' #' @export -print.dabest <- function(x, ...) { +print.dabest <- function(x, print_greet_end = TRUE, ...) { + dabest_obj <- x check_dabest_object(dabest_obj) - - print_greeting_header() + cat("\n") + if (print_greet_end) { + print_greeting_header() + } + else cat("\n") paired <- dabest_obj$paired ci <- dabest_obj$ci # Use a lookup table for rm_status and paired_status - rm_status_lookup <- c(NULL = "", "sequential" = "for the sequential design of repeated-measures experiment \\n", "baseline" = "for repeated measures against baseline \\n") - paired_status_lookup <- c(NULL = "E", "sequential" = "Paired e", "baseline" = "Paired e") + rm_status_lookup <- c(NULL = "", "sequential" = "for the sequential design of repeated-measures experiment \n", "baseline" = "for repeated measures against baseline \n") + paired_status_lookup <- c(NULL = "Unpaired ", "sequential" = "Paired ", "baseline" = "Paired ") - rm_status <- rm_status_lookup[paired] - paired_status <- paired_status_lookup[paired] + rm_status <- rm_status_lookup[[format(paired)]] + paired_status <- paired_status_lookup[[format(paired)]] # Create strings - line1 <- paste0(paired_status, "ffect size(s) ", rm_status) + line1 <- paste0(paired_status, "effect size(s) ", rm_status) line2 <- paste0("with ", ci, "% confidence intervals will be computed for:") cat(line1) cat(line2) cat("\n") print_each_comparism(dabest_obj) - print_ending(dabest_obj) + if (print_greet_end) { + print_ending(dabest_obj) + } } diff --git a/R/001_effsize_func.R b/R/001_effsize_func.R index 804bad3..7a0083f 100644 --- a/R/001_effsize_func.R +++ b/R/001_effsize_func.R @@ -307,6 +307,7 @@ cohens_h <- function(dabest_obj, perm_count = 5000) { #' @noRd #' #' @param x a dabest_effectsize_obj object, set as x to tally with method signature for print functions +#' @param print_greet_end a boolean value for printing greeting/ending. #' @param ... S3 signature for generic plot function. #' #' @return A summary of the effect sizes and respective confidence intervals. @@ -327,14 +328,18 @@ cohens_h <- function(dabest_obj, perm_count = 5000) { #' print(dabest_obj.mean_diff) #' #' @export -print.dabest_effectsize <- function(x, ...) { +print.dabest_effectsize <- function(x, print_greet_end = TRUE, ...) { dabest_effectsize_obj <- x check_effectsize_object(dabest_effectsize_obj) - - print_greeting_header() + if (print_greet_end) { + print_greeting_header() + } + else cat("\n") es <- dabest_effectsize_obj$effect_size_type print_each_comparism_effectsize(dabest_effectsize_obj, es) - print_ending(dabest_effectsize_obj) + if (print_greet_end) { + print_ending(dabest_effectsize_obj) + } } diff --git a/R/005_printing.R b/R/005_printing.R index 424f5bb..1d72ac6 100644 --- a/R/005_printing.R +++ b/R/005_printing.R @@ -107,11 +107,11 @@ print_each_comparism_effectsize <- function(dabest_effectsize_obj, effectsize) { pvalue <- dabest_effectsize_obj$permtest_pvals$pval_for_tests # Use a lookup table for rm_status and paired_status - rm_status_lookup <- c(NULL = "", "sequential" = "for the sequential design of repeated-measures experiment \\n", "baseline" = "for repeated measures against baseline \\n") + rm_status_lookup <- c(NULL = "", "sequential" = "for the sequential design of repeated-measures experiment \n", "baseline" = "for repeated measures against baseline \n") paired_status_lookup <- c(NULL = "unpaired", "sequential" = "paired", "baseline" = "paired") - rm_status <- rm_status_lookup[paired] - paired_status <- paired_status_lookup[paired] + rm_status <- rm_status_lookup[[format(paired)]] # make sure even NULL gets converted to string + paired_status <- paired_status_lookup[[format(paired)]] # make sure even NULL gets converted to string if (is.list(dabest_effectsize_obj$idx)) { for (group in dabest_effectsize_obj$idx) { @@ -133,7 +133,7 @@ print_each_comparism_effectsize <- function(dabest_effectsize_obj, effectsize) { current_ci <- ci[i] current_pval <- pvalue[i] - cat(stringr::str_interp("The ${paired_status} ${es} between ${current_test_group} and ${control_group} is ${current_difference} [${current_ci}%CI ${current_bca_low}, ${current_bca_high}].\n")) + cat(stringr::str_interp("The ${paired_status} ${es} between ${current_test_group} and ${control_group} is ${current_difference}, ${current_ci}% CI [${current_bca_low}, ${current_bca_high}].\n")) cat(stringr::str_interp("The p-value of the two-sided permutation t-test is ${sprintf(current_pval, fmt = '%#.4f')}, calculated for legacy purposes only.")) cat("\n\n") i <- i + 1 @@ -149,7 +149,7 @@ print_each_comparism_effectsize <- function(dabest_effectsize_obj, effectsize) { current_ci <- ci[i] current_pval <- pvalue[i] - cat(stringr::str_interp("The ${paired_status} ${es} between ${current_group} and ${previous_group} is ${current_difference} [${current_ci}%CI ${current_bca_low}, ${current_bca_high}].\n")) + cat(stringr::str_interp("The ${paired_status} ${es} between ${current_group} and ${previous_group} is ${current_difference}, ${current_ci}% CI [${current_bca_low}, ${current_bca_high}].\n")) cat(stringr::str_interp("The p-value of the two-sided permutation t-test is ${sprintf(current_pval, fmt = '%#.4f')}, calculated for legacy purposes only.")) cat("\n\n") i <- i + 1 @@ -161,7 +161,7 @@ print_each_comparism_effectsize <- function(dabest_effectsize_obj, effectsize) { test_groups <- dabest_effectsize_obj$idx[2:length(dabest_effectsize_obj$idx)] for (current_test_group in test_groups) { - cat(stringr::str_interp("The ${paired_status} ${es} between ${current_test_group} and ${control_group} is ${difference} [${ci}%CI ${bca_low}, ${bca_high}].\n")) + cat(stringr::str_interp("The ${paired_status} ${es} between ${current_test_group} and ${control_group} is ${difference}, ${ci}% CI [${bca_low}, ${bca_high}].\n")) cat(stringr::str_interp("The p-value of the two-sided permutation t-test is ${sprintf(current_pval, fmt = '%#.4f')}, calculated for legacy purposes only.\n")) } } diff --git a/R/999_plot_palettes.R b/R/999_plot_palettes.R index 3c976b3..d27d716 100644 --- a/R/999_plot_palettes.R +++ b/R/999_plot_palettes.R @@ -5,37 +5,45 @@ # Applies palettes to objects # TODO add proper documentation. apply_palette <- function(ggplot_object, palette_name) { - ggplot_object <- switch(palette_name, - "npg" = - ggplot_object + ggsci::scale_color_npg() + ggsci::scale_fill_npg(), - "aaas" = - ggplot_object + ggsci::scale_color_aaas() + ggsci::scale_fill_aaas(), - "nejm" = - ggplot_object + ggsci::scale_color_nejm() + ggsci::scale_fill_nejm(), - "lancet" = - ggplot_object + ggsci::scale_color_lancet() + ggsci::scale_fill_lancet(), - "jama" = - ggplot_object + ggsci::scale_color_jama() + ggsci::scale_fill_jama(), - "jco" = - ggplot_object + ggsci::scale_color_jco() + ggsci::scale_fill_jco(), - "ucscgb" = - ggplot_object + ggsci::scale_color_ucscgb() + ggsci::scale_fill_ucscgb(), - "d3" = - ggplot_object + ggsci::scale_color_d3() + ggsci::scale_fill_d3(), - "locuszoom" = - ggplot_object + ggsci::scale_color_locuszoom() + ggsci::scale_fill_locuszoom(), - "igv" = - ggplot_object + ggsci::scale_color_igv() + ggsci::scale_fill_igv(), - "cosmic" = - ggplot_object + ggsci::scale_color_cosmic() + ggsci::scale_fill_cosmic(), - "uchicago" = - ggplot_object + ggsci::scale_color_uchicago() + ggsci::scale_fill_uchicago(), - "brewer" = - ggplot_object + ggplot2::scale_color_brewer() + ggplot2::scale_fill_brewer(), - "ordinal" = - ggplot_object + ggplot2::scale_color_ordinal() + ggplot2::scale_fill_ordinal(), - "viridis_d" = - ggplot_object + ggplot2::scale_color_viridis_d() + ggplot2::scale_fill_viridis_d() + ggplot_object <- switch( + palette_name, + "npg" = ggplot_object + ggsci::scale_color_npg() + ggsci::scale_fill_npg(), + "aaas" = ggplot_object + + ggsci::scale_color_aaas() + + ggsci::scale_fill_aaas(), + "nejm" = ggplot_object + + ggsci::scale_color_nejm() + + ggsci::scale_fill_nejm(), + "lancet" = ggplot_object + + ggsci::scale_color_lancet() + + ggsci::scale_fill_lancet(), + "jama" = ggplot_object + + ggsci::scale_color_jama() + + ggsci::scale_fill_jama(), + "jco" = ggplot_object + ggsci::scale_color_jco() + ggsci::scale_fill_jco(), + "ucscgb" = ggplot_object + + ggsci::scale_color_ucscgb() + + ggsci::scale_fill_ucscgb(), + "d3" = ggplot_object + ggsci::scale_color_d3() + ggsci::scale_fill_d3(), + "locuszoom" = ggplot_object + + ggsci::scale_color_locuszoom() + + ggsci::scale_fill_locuszoom(), + "igv" = ggplot_object + ggsci::scale_color_igv() + ggsci::scale_fill_igv(), + "cosmic" = ggplot_object + + ggsci::scale_color_cosmic() + + ggsci::scale_fill_cosmic(), + "uchicago" = ggplot_object + + ggsci::scale_color_uchicago() + + ggsci::scale_fill_uchicago(), + "brewerDark2" = ggplot_object + + ggplot2::scale_color_brewer(palette = "Dark2") + + ggplot2::scale_fill_brewer(palette = "Dark2"), + "ordinal" = ggplot_object + + ggplot2::scale_color_ordinal() + + ggplot2::scale_fill_ordinal(), + "viridis_d" = ggplot_object + + ggplot2::scale_color_viridis_d() + + ggplot2::scale_fill_viridis_d() ) return(ggplot_object) @@ -43,7 +51,8 @@ apply_palette <- function(ggplot_object, palette_name) { get_palette_colours <- function(palette_name, num_colours) { # palette function by name - colours <- switch(palette_name, + colours <- switch( + palette_name, "npg" = ggsci::pal_npg()(num_colours), "aaas" = ggsci::pal_aaas()(num_colours), "nejm" = ggsci::pal_nejm()(num_colours), @@ -56,7 +65,7 @@ get_palette_colours <- function(palette_name, num_colours) { "igv" = ggsci::pal_igv()(num_colours), "cosmic" = ggsci::pal_cosmic()(num_colours), "uchicago" = ggsci::pal_uchicago()(num_colours), - "brewer" = RColorBrewer::brewer.pal()(num_colours), + "brewerDark2" = RColorBrewer::brewer.pal(name = "Dark2", n = num_colours), "ordinal" = viridisLite::viridis(n = num_colours, option = "viridis"), "viridis_d" = viridisLite::viridis(n = num_colours, option = "viridis") ) diff --git a/tests/testthat/test_002_plot_components.R b/tests/testthat/test_002_plot_components.R index d553d1e..815ad47 100644 --- a/tests/testthat/test_002_plot_components.R +++ b/tests/testthat/test_002_plot_components.R @@ -12,7 +12,7 @@ describe("Testing add_scaling_component_to_delta_plot function", { expect_type(result, "list") expect_equal(length(result), 3) # 3 components returned # Check delta_plot component - expect_type(result[[1]], "list") + expect_true(ggplot2::is_ggplot(result[[1]])) # TODO Add specific expectations to check if the components are created correctly }) })