diff --git a/R/report_htest_chi2.R b/R/report_htest_chi2.R index cfbe8231..e051f001 100644 --- a/R/report_htest_chi2.R +++ b/R/report_htest_chi2.R @@ -19,9 +19,9 @@ table_footer <- attributes(table)$table_footer ci <- attributes(table)$ci estimate <- names(table)[1] - rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) + dot_args$rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) - es_args <- c(list(table, rules = rules), dot_args) + es_args <- c(list(table), dot_args) interpretation <- do.call(effectsize::interpret, es_args)$Interpretation rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name")) @@ -65,7 +65,7 @@ .report_model_chi2 <- function(x, table) { if (chi2_type(x) == "pearson") { type <- " of independence between" - vars_full <- paste0(names(attributes(x$observed)$dimnames), collapse = " and ") + vars_full <- paste(names(attributes(x$observed)$dimnames), collapse = " and ") } else if (chi2_type(x) == "probabilities") { type <- " / goodness of fit of " distr <- ifelse( diff --git a/R/report_htest_fisher.R b/R/report_htest_fisher.R index a1f95f74..b8e5da98 100644 --- a/R/report_htest_fisher.R +++ b/R/report_htest_fisher.R @@ -9,37 +9,28 @@ # report_effectsize --------------------- .report_effectsize_fisher <- function(x, table, dot_args, rules = "funder2019") { - args <- c(list(x), dot_args) - table <- do.call(effectsize::effectsize, args) + es_args <- c(list(x), dot_args) + table <- do.call(effectsize::effectsize, es_args) ci <- attributes(table)$ci estimate <- names(table)[1] - rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) + dot_args$rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) - args <- c(list(table, rules = rules), dot_args) - interpretation <- do.call(effectsize::interpret, args)$Interpretation + es_args <- c(list(table), dot_args) + interpretation <- do.call(effectsize::interpret, es_args)$Interpretation rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name")) - if (estimate == "Cramers_v_adjusted") { - main <- paste0("Adjusted Cramer's v = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Tschuprows_t") { - main <- paste0("Tschuprow's t = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Tschuprows_t_adjusted") { - main <- paste0("Adjusted Tschuprow's t = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Pearsons_c") { - main <- paste0("Pearson's c = ", insight::format_value(table[[estimate]])) - } else if (estimate == "phi_adjusted") { - main <- paste0("Adjusted Phi = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Cohens_h") { - main <- paste0("Cohen's h = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Odds_ratio") { - main <- paste0("Odds ratio = ", insight::format_value(table[[estimate]])) - } else if (estimate == "Ris_kratio") { - main <- paste0("Risk ratio = ", insight::format_value(table[[estimate]])) - } else if (estimate == "cohens_h") { - main <- paste0("Cohen's w = ", insight::format_value(table[[estimate]])) - } else { - main <- paste0(estimate, " = ", insight::format_value(table[[estimate]])) - } + main <- switch(estimate, + Cramers_v_adjusted = paste0("Adjusted Cramer's v = ", insight::format_value(table[[estimate]])), + Tschuprows_t = paste0("Tschuprow's t = ", insight::format_value(table[[estimate]])), + Tschuprows_t_adjusted = paste0("Adjusted Tschuprow's t = ", insight::format_value(table[[estimate]])), + Pearsons_c = paste0("Pearson's c = ", insight::format_value(table[[estimate]])), + phi_adjusted = paste0("Adjusted Phi = ", insight::format_value(table[[estimate]])), + Cohens_h = paste0("Cohen's h = ", insight::format_value(table[[estimate]])), + Odds_ratio = paste0("Odds ratio = ", insight::format_value(table[[estimate]])), + Ris_kratio = paste0("Risk ratio = ", insight::format_value(table[[estimate]])), + cohens_h = paste0("Cohen's w = ", insight::format_value(table[[estimate]])), + paste0(estimate, " = ", insight::format_value(table[[estimate]])) + ) statistics <- paste0( main, @@ -64,15 +55,15 @@ # report_model ---------------------------- .report_model_fisher <- function(x, table) { - vars_full <- paste0(names(attributes(x$observed)$dimnames), collapse = " and ") + vars_full <- paste(names(attributes(x$observed)$dimnames), collapse = " and ") - text <- paste0( + final_text <- paste0( trimws(x$method), " testing the association between the variables of the ", x$data.name, " dataset " ) - text + final_text } chi2_type <- function(x) { diff --git a/R/report_htest_ttest.R b/R/report_htest_ttest.R index a30b3aac..0bd3dcc5 100644 --- a/R/report_htest_ttest.R +++ b/R/report_htest_ttest.R @@ -44,14 +44,14 @@ # report_effectsize --------------------- .report_effectsize_ttest <- function(x, table, dot_args, type, rules = "cohen1988") { - my_args <- c(list(x), dot_args) - table <- do.call(effectsize::effectsize, my_args) + es_args <- c(list(x), dot_args) + table <- do.call(effectsize::effectsize, es_args) ci <- attributes(table)$ci estimate <- names(table)[1] - rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) + dot_args$rules <- ifelse(is.null(dot_args$rules), rules, dot_args$rules) - my_args <- c(list(table, rules = rules), dot_args) - interpretation <- do.call(effectsize::interpret, my_args)$Interpretation + es_args <- c(list(table), dot_args) + interpretation <- do.call(effectsize::interpret, es_args)$Interpretation rules <- .text_effectsize(attr(attr(interpretation, "rules"), "rule_name")) if (estimate %in% c("d", "Cohens_d")) { diff --git a/tests/testthat/_snaps/windows/report.htest-correlation.md b/tests/testthat/_snaps/windows/report.htest-correlation.md index 30968158..8f6b9d01 100644 --- a/tests/testthat/_snaps/windows/report.htest-correlation.md +++ b/tests/testthat/_snaps/windows/report.htest-correlation.md @@ -12,10 +12,7 @@ --- Code - report(cor.test(mtcars$wt, mtcars$mpg, method = "spearman")) - Condition - Warning in `cor.test.default()`: - Cannot compute exact p-value with ties + report(suppressWarnings(cor.test(mtcars$wt, mtcars$mpg, method = "spearman"))) Output Effect sizes were labelled following Funder's (2019) recommendations. @@ -26,10 +23,7 @@ --- Code - report(cor.test(mtcars$wt, mtcars$mpg, method = "kendall")) - Condition - Warning in `cor.test.default()`: - Cannot compute exact p-value with ties + report(suppressWarnings(cor.test(mtcars$wt, mtcars$mpg, method = "kendall"))) Output Effect sizes were labelled following Funder's (2019) recommendations. diff --git a/tests/testthat/test-report.htest-correlation.R b/tests/testthat/test-report.htest-correlation.R index 46fd9171..a14b471f 100644 --- a/tests/testthat/test-report.htest-correlation.R +++ b/tests/testthat/test-report.htest-correlation.R @@ -17,8 +17,14 @@ test_that("report.htest-correlation", { expect_snapshot(variant = "windows", report(cor.test(mtcars$wt, mtcars$mpg))) set.seed(123) - expect_snapshot(variant = "windows", report(cor.test(mtcars$wt, mtcars$mpg, method = "spearman"))) + expect_snapshot(variant = "windows", report(suppressWarnings(cor.test( + mtcars$wt, mtcars$mpg, + method = "spearman" + )))) set.seed(123) - expect_snapshot(variant = "windows", report(cor.test(mtcars$wt, mtcars$mpg, method = "kendall"))) + expect_snapshot(variant = "windows", report(suppressWarnings(cor.test( + mtcars$wt, mtcars$mpg, + method = "kendall" + )))) })