diff --git a/DESCRIPTION b/DESCRIPTION index b634d97b..c9317338 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: report Type: Package Title: Automated Reporting of Results and Statistical Models -Version: 0.6.1.2 +Version: 0.6.1.3 Authors@R: c(person(given = "Dominique", family = "Makowski", diff --git a/NEWS.md b/NEWS.md index 2becfea3..9643d141 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ Bug fixes +* Added regression tests for `reformulate()` formula edge cases to prevent future issues (#391) * Fixed issue with missing effect size for the Intercept term in type 3 anova tables (#451) # report 0.6.1 diff --git a/tests/testthat/test-report.lm.R b/tests/testthat/test-report.lm.R index 12a64552..5e99fd7c 100644 --- a/tests/testthat/test-report.lm.R +++ b/tests/testthat/test-report.lm.R @@ -39,3 +39,46 @@ test_that("report.lm - lm intercept-only", { out <- suppressWarnings(report(model_io, verbose = FALSE)) expect_snapshot(variant = "windows", out) }) + + +test_that("report.lm - reformulate formula edge cases", { + # Test various reformulate scenarios to prevent regression of issue #391 + + # Test 1: Simple reformulate case + model_reform <- lm(reformulate(c("wt", "hp"), "mpg"), data = mtcars) + result_reform <- report(model_reform) + expect_s3_class(result_reform, "report") + expect_true(any(grepl("wt", as.character(result_reform)))) + expect_true(any(grepl("hp", as.character(result_reform)))) + + # Test 2: Reformulate with formula() wrapper (exact issue case) + model_formula <- lm(formula(reformulate(c("wt", "hp"), "mpg")), data = mtcars) + result_formula <- report(model_formula) + expect_s3_class(result_formula, "report") + expect_true(any(grepl("wt", as.character(result_formula)))) + expect_true(any(grepl("hp", as.character(result_formula)))) + + # Test 3: Reformulate with interaction terms + model_interact <- lm(reformulate(c("wt", "hp", "wt:hp"), "mpg"), data = mtcars) + result_interact <- report(model_interact) + expect_s3_class(result_interact, "report") + expect_true(any(grepl("wt", as.character(result_interact)))) + expect_true(any(grepl("hp", as.character(result_interact)))) + + # Test 4: Reformulate without intercept + model_no_int <- lm(reformulate(c("wt", "hp"), "mpg", intercept = FALSE), data = mtcars) + result_no_int <- report(model_no_int) + expect_s3_class(result_no_int, "report") + expect_true(any(grepl("wt", as.character(result_no_int)))) + expect_true(any(grepl("hp", as.character(result_no_int)))) + + # Test 5: Verify format_formula works correctly with reformulate + formatted_reform <- format_formula(model_reform) + formatted_normal <- format_formula(lm(mpg ~ wt + hp, data = mtcars)) + expect_equal(formatted_reform, formatted_normal) + + # Test 6: Verify report_model works correctly with reformulate + model_report_reform <- report_model(model_reform) + model_report_normal <- report_model(lm(mpg ~ wt + hp, data = mtcars)) + expect_equal(as.character(model_report_reform), as.character(model_report_normal)) +})