From 49ba03d4e00641c07cdcfea4fa94180a3edb43c4 Mon Sep 17 00:00:00 2001 From: "Simon P. Couch" Date: Mon, 11 Apr 2022 15:43:51 -0400 Subject: [PATCH] clarify warning for un-maintained tidiers --- NEWS.md | 2 +- R/stats-glm-tidiers.R | 6 +++--- R/stats-lm-tidiers.R | 6 +++--- R/utilities.R | 6 +++--- tests/testthat/test-utilities.R | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/NEWS.md b/NEWS.md index 490aa217e..59ccbdd09 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,7 +8,7 @@ While broom 0.8.0 does not introduce much in terms of new functionality or break - All tidiers now have example code demonstrating usage in their documentation. Tidiers for base packages as well as selected others also include sample code for visualization of results with ggplot2. - Code examples in the documentation largely now follow consistent style---these changes were made largely to reflect the tidyverse style guide, addressing spacing, object naming, and commenting, among other things. - Examples previously marked with `\dontrun` or `\donttest` have been workshopped to run reliably. -* Clarify errors and warnings for deprecated tidiers. +* Clarify errors and warnings for deprecated and un-maintained tidiers. * Ensure that tidiers are placed in files named according to the model-supplying package rather than the model object class for easier navigability of the source code. ### Bug fixes and other improvements diff --git a/R/stats-glm-tidiers.R b/R/stats-glm-tidiers.R index cb5ab574a..93fd35ffa 100644 --- a/R/stats-glm-tidiers.R +++ b/R/stats-glm-tidiers.R @@ -13,7 +13,7 @@ tidy.glm <- function(x, conf.int = FALSE, conf.level = .95, exponentiate = FALSE, ...) { warn_on_appropriated_glm_class(x) - warn_on_subclass(x) + warn_on_subclass(x, "tidy") ret <- as_tibble(summary(x)$coefficients, rownames = "term") colnames(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") @@ -75,7 +75,7 @@ augment.glm <- function(x, type.residuals = c("deviance", "pearson"), se_fit = FALSE, ...) { warn_on_appropriated_glm_class(x) - warn_on_subclass(x) + warn_on_subclass(x, "augment") type.predict <- rlang::arg_match(type.predict) type.residuals <- rlang::arg_match(type.residuals) @@ -136,7 +136,7 @@ augment.glm <- function(x, #' @seealso [stats::glm()] glance.glm <- function(x, ...) { warn_on_appropriated_glm_class(x) - warn_on_subclass(x) + warn_on_subclass(x, "glance") as_glance_tibble( null.deviance = x$null.deviance, diff --git a/R/stats-lm-tidiers.R b/R/stats-lm-tidiers.R index 377b29f10..b658a3f53 100644 --- a/R/stats-lm-tidiers.R +++ b/R/stats-lm-tidiers.R @@ -91,7 +91,7 @@ #' @family lm tidiers tidy.lm <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { - warn_on_subclass(x) + warn_on_subclass(x, "tidy") ret <- as_tibble(summary(x)$coefficients, rownames = "term") colnames(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") @@ -143,7 +143,7 @@ tidy.lm <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { augment.lm <- function(x, data = model.frame(x), newdata = NULL, se_fit = FALSE, interval = c("none", "confidence", "prediction"), ...) { - warn_on_subclass(x) + warn_on_subclass(x, "augment") interval <- match.arg(interval) df <- augment_newdata(x, data, newdata, se_fit, interval) @@ -190,7 +190,7 @@ augment.lm <- function(x, data = model.frame(x), newdata = NULL, #' @family lm tidiers glance.lm <- function(x, ...) { - warn_on_subclass(x) + warn_on_subclass(x, "glance") # check whether the model was fitted with only an intercept, in which # case drop the fstatistic related columns diff --git a/R/utilities.R b/R/utilities.R index d5200e1b4..3c1262516 100644 --- a/R/utilities.R +++ b/R/utilities.R @@ -485,15 +485,15 @@ broom_confint_terms <- function(x, ...) { } # warn when models subclasses glm/lm and do not have their own dedicated tidiers. -warn_on_subclass <- function(x) { +warn_on_subclass <- function(x, tidier) { if (length(class(x)) > 1 && class(x)[1] != "glm") { subclass <- class(x)[1] dispatched_method <- class(x)[class(x) %in% c("glm", "lm")][1] warning( - "Tidiers for objects of class ", + "The `", tidier, "()` method for objects of class ", subclass, - " are not maintained by the broom team, and are only supported through ", + " is not maintained by the broom team, and is only supported through ", "the ", dispatched_method, " tidier method. Please be cautious in interpreting and reporting ", diff --git a/tests/testthat/test-utilities.R b/tests/testthat/test-utilities.R index 573f02011..756abf11b 100644 --- a/tests/testthat/test-utilities.R +++ b/tests/testthat/test-utilities.R @@ -93,14 +93,14 @@ test_that("appropriate warning on (g)lm-subclassed models", { class(x) <- c("gee", "glm") expect_warning( - warn_on_subclass(x), + warn_on_subclass(x, "tidy"), "only supported through the glm tidier method." ) class(x) <- c("gee", "glm", "lm") expect_warning( - warn_on_subclass(x), + warn_on_subclass(x, "tidy"), "only supported through the glm tidier method." ) })