Skip to content

Commit

Permalink
fix "formal argument "rules" matched by multiple actual arguments" (#447
Browse files Browse the repository at this point in the history
)

* fix "formal argument "rules" matched by multiple actual arguments"

* fix lints

* styling

* fix check-test-warnings workflow

* styling [skip ci]
  • Loading branch information
rempsyc authored Jul 4, 2024
1 parent b94b37f commit 28c16aa
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 48 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Config/testthat/edition: 3
Config/Needs/website:
rstudio/bslib,
Expand Down
6 changes: 3 additions & 3 deletions R/report_htest_chi2.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))

Expand Down Expand Up @@ -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(
Expand Down
49 changes: 20 additions & 29 deletions R/report_htest_fisher.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
10 changes: 5 additions & 5 deletions R/report_htest_ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand Down
10 changes: 2 additions & 8 deletions tests/testthat/_snaps/windows/report.htest-correlation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions tests/testthat/test-report.htest-correlation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"
))))
})

0 comments on commit 28c16aa

Please sign in to comment.