parameters icon indicating copy to clipboard operation
parameters copied to clipboard

Export more `S3` methods for `model_parameters()` generic

Open IndrajeetPatil opened this issue 1 year ago • 8 comments

A lot of the objects listed below are actually supported in parameters, but developers who will be comparing it with broom will think they aren't because there are no exported methods in NAMESPACE.

broom_tidy <- ls(getNamespace("broom"))
broom_tidy <- broom_tidy[grepl("^tidy", broom_tidy)]
broom_supported <- gsub("^tidy.", "", broom_tidy)
easystats_tidy <- ls(getNamespace("parameters"))
easystats_tidy <- easystats_tidy[grepl("^model_parameters", easystats_tidy)]
easystats_supported <- gsub("^model_parameters.", "", easystats_tidy)

broom_supported[!broom_supported %in% easystats_supported]
#>   [1] "emmeans"                  "emmeans_summary"         
#>   [3] "irlba"                    "optim"                   
#>   [5] "svd"                      "xyz"                     
#>   [7] "aareg"                    "acf"                     
#>   [9] "Arima"                    "biglm"                   
#>  [11] "binDesign"                "binWidth"                
#>  [13] "boot"                     "btergm"                  
#>  [15] "cch"                      "character"               
#>  [17] "cld"                      "clm"                     
#>  [19] "confint.glht"             "confusionMatrix"         
#>  [21] "coxph"                    "crr"                     
#>  [23] "cv.glmnet"                "density"                 
#>  [25] "dgCMatrix"                "dgTMatrix"               
#>  [27] "dist"                     "drc"                     
#>  [29] "durbinWatsonTest"         "ergm"                    
#>  [31] "factanal"                 "felm"                    
#>  [33] "fixest"                   "ftable"                  
#>  [35] "garch"                    "geeglm"                  
#>  [37] "glmnet"                   "glmrob"                  
#>  [39] "glmRob"                   "gmm"                     
#>  [41] "ivreg"                    "kappa"                   
#>  [43] "kde"                      "Kendall"                 
#>  [45] "leveneTest"               "Line"                    
#>  [47] "Lines"                    "lm"                      
#>  [49] "lm.beta"                  "lmrob"                   
#>  [51] "lmRob"                    "logical"                 
#>  [53] "lsmobj"                   "manova"                  
#>  [55] "map"                      "mfx"                     
#>  [57] "mlogit"                   "muhaz"                   
#>  [59] "nlrq"                     "nls"                     
#>  [61] "NULL"                     "numeric"                 
#>  [63] "orcutt"                   "plm"                     
#>  [65] "poLCA"                    "Polygon"                 
#>  [67] "Polygons"                 "power.htest"             
#>  [69] "prcomp"                   "pyears"                  
#>  [71] "rcorr"                    "ref.grid"                
#>  [73] "regsubsets"               "rlm"                     
#>  [75] "roc"                      "rq"                      
#>  [77] "sarlm"                    "Sarlm"                   
#>  [79] "sparseMatrix"             "SpatialLinesDataFrame"   
#>  [81] "SpatialPolygons"          "SpatialPolygonsDataFrame"
#>  [83] "spec"                     "speedglm"                
#>  [85] "speedlm"                  "summary_emm"             
#>  [87] "summary.glht"             "summary.lm"              
#>  [89] "summary.plm"              "summaryDefault"          
#>  [91] "survdiff"                 "survexp"                 
#>  [93] "survfit"                  "survreg"                 
#>  [95] "svyolr"                   "table"                   
#>  [97] "tobit"                    "ts"                      
#>  [99] "TukeyHSD"                 "zoo"

Created on 2022-07-17 by the reprex package (v2.0.1)

This is because most of them are supported by the default method:

library(parameters)
library(speedglm)
#> Loading required package: Matrix
#> Loading required package: MASS

sloop::s3_dispatch(model_parameters(lm(wt ~ mpg, mtcars)))
#>    model_parameters.lm
#> => model_parameters.default

Created on 2022-07-17 by the reprex package (v2.0.1)

I think we just need to do something like-

#' @export
model_parameters.lm <- model_parameters.default

This is low priority, and probably easy enough to be handled by newcomers.

IndrajeetPatil avatar Jul 17 '22 14:07 IndrajeetPatil

If someone implements this, all of the assignments should be stacked like:

model_parameters.a <- 
  model_parameters.b <-
  model_parameteters.default

bwiernik avatar Jul 17 '22 14:07 bwiernik

But, IINM, model_parameters.b won't appear in NAMESPACE if we do it this way.

We'll need to do something like this if both of them are to appear in NAMESPACE:

#' @export
model_parameters.a <- model_parameteters.default

#' @export
model_parameters.b <- model_parameteters.default  

IndrajeetPatil avatar Jul 17 '22 14:07 IndrajeetPatil

But, IINM, model_parameters.b won't appear in NAMESPACE if we do it this way.

Yes, I can confirm that this is the case. Just tried it with the code below, and the middle ones in the chain disappear from NAMESPACE:

https://github.com/easystats/parameters/blob/47b6c0ce35c6c86c085ac17ac537acb1eba989fe/R/methods_quantreg.R#L42-L59

IndrajeetPatil avatar Jul 17 '22 14:07 IndrajeetPatil

Hmmm, there's a way, let me see what I did before

Edit: ah nope, I was misremembering.

bwiernik avatar Jul 17 '22 16:07 bwiernik

Okay. Thanks for checking!

That would have indeed been cleaner if it were supported. Is it that roxygen2 can't handle this, or that R itself doesn't support it?

Just wondering if we can make a feature request.

IndrajeetPatil avatar Jul 22 '22 12:07 IndrajeetPatil

But, regardless, at least for now we can just do the following:

#' @export
model_parameters.a <- model_parameteters.default

#' @export
model_parameters.b <- model_parameteters.default  

IndrajeetPatil avatar Jul 22 '22 12:07 IndrajeetPatil

It's a Roxygen limitation

bwiernik avatar Jul 22 '22 15:07 bwiernik

In a PR, I the added export S3 methods for model_parameters() generic:

Just as FYI reference, here is clumsy code I used:

missing classes

x <- broom_supported[!broom_supported %in% easystats_supported]

and to construct this

#' @export model_parameters.CLASS <- model_parameters.default

use clumsy code

cat(vapply(x, function(x) { paste0("#' @export\n", "model_parameters.",x, " <- model_parameters.default\n\n")}, character(length = 1), USE.NAMES=F)

)

ALSO, I found this *without* function a little easier to decipher:

"%w/o%" <- function(x, y) x[!x %in% y] #-- x without y x <- broom_supported %w/o% easystats_supported

jimrothstein avatar Oct 20 '22 05:10 jimrothstein