tidymodels / broom

Convert statistical analysis objects from R into tidy format
https://broom.tidymodels.org
Other
1.45k stars 304 forks source link

warn_on_glm2 breaks with method function #1058

Closed gravesti closed 3 years ago

gravesti commented 3 years ago

The problem

The warn_on_glm2 function causes an error for a stats::glm object where the method argument has been given a function. From the glm docs, for the method argument:

the method to be used in fitting the model. The default method "glm.fit" uses iteratively reweighted least squares (IWLS): the alternative "model.frame" returns the model frame and does no fitting.

User-supplied fitting functions can be supplied either as a function or a character string naming a function, with a function which takes the same arguments as glm.fit. If specified as a character string it is looked up from within the stats namespace.

and the method vaue:

the name of the fitter function used (when provided as a character string to glm()) or the fitter function (when provided as that).

The trouble seems to be here, where we test equality between a function and a character. https://github.com/tidymodels/broom/blob/0f4c1caa8d7c3f7162849c3d892e522a913ed966/R/stats-glm-tidiers.R#L166

Reproducible example

## Based on the example from the glm documentation
## Dobson (1990) Page 93: Randomized Controlled Trial :
counts <- c(18,17,15,20,10,20,25,13,12)
outcome <- gl(3,1,9)
treatment <- gl(3,3)
glm.D93 <- glm(counts ~ outcome + treatment, family = poisson(),
               method = glm.fit)

broom::tidy(glm.D93)
#> Error in x$method == "glm.fit2": comparison (1) is possible only for atomic and list types
github-actions[bot] commented 2 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.