diff --git a/NEWS.md b/NEWS.md index 4baaa9f6..3b4df89e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,9 @@ +# report (devel) + +Bug fixes + +* Fixed an issue in `report()` where the reference level for logical predictors was incorrectly displayed as `[?]` instead of `FALSE` for the intercept (@M-Colley, #598). + # report 0.6.4 New features diff --git a/R/report_intercept.R b/R/report_intercept.R index 39dc27ad..105967e4 100644 --- a/R/report_intercept.R +++ b/R/report_intercept.R @@ -98,6 +98,13 @@ print.report_intercept <- function(x, ...) { intercept_text, paste0(col, " = ", levels(intercept_data[[col]])[ref_level]) ) + } else if (is.logical(intercept_data[[col]])) { + logical_factor <- as.factor(intercept_data[[col]]) + ref_level <- .find_reference_level(logical_factor) + intercept_text <- c( + intercept_text, + paste0(col, " = ", levels(logical_factor)[ref_level]) + ) } else { intercept_text <- c(intercept_text, paste0(col, " = [?]")) } diff --git a/tests/testthat/test-report_intercept.R b/tests/testthat/test-report_intercept.R index 5baedbac..aefee02b 100644 --- a/tests/testthat/test-report_intercept.R +++ b/tests/testthat/test-report_intercept.R @@ -49,4 +49,14 @@ test_that("reflevel", { as.character(report_intercept(m3)), "The model's intercept, corresponding to f = 1, is at 0.17 (95% CI [-0.47, 0.81], t(27) = 0.55, p = 0.584)." ) + + # Logical predictor + on.exit(data("mtcars"), add = TRUE) + + mtcars$more_than_4_cyl <- as.logical(mtcars$cyl > 4) + m4 <- lm(mpg ~ more_than_4_cyl, data = mtcars) + expect_identical( + as.character(report_intercept(m4)), + "The model's intercept, corresponding to more_than_4_cyl = FALSE, is at 26.66 (95% CI [24.41, 28.92], t(30) = 24.16, p < .001)." + ) })