bbolker / broom.mixed

tidy methods for mixed models in R
227 stars 23 forks source link

Call to glmmTMB:::as.data.frame.ranef.glmmTMB is broken now #103

Closed bschulth closed 3 years ago

bschulth commented 3 years ago

In broom.mixed:::tidy.glmmTMB, a call is made to as.data.frame() with argument stringsAsFactors = FALSE on a 'ranef.gmlmTMB' object at: https://github.com/bbolker/broom.mixed/blob/master/R/glmmTMB_tidiers.R#L257 .

However in the 1.0.2.1 release of glmmTMB on 2020-07-02, it looks like they changed the functionality to no longer accept the stringsAsFactor argument.

glmmTMB:::as.data.frame.ranef.glmmTMB (see https://github.com/glmmTMB/glmmTMB/blob/e83c7651abbfeba37ecb1d21c944b35eab5a719c/glmmTMB/R/methods.R#L1181) specifically, they changed their internal glmmTMB:::check_dots function (see https://github.com/glmmTMB/glmmTMB/blob/master/glmmTMB/R/utils.R#L683) to no longer support stringsAsFactors as an argment.

Example: # glmmTMB: 1.0.2.1 # broom.mixed: 0.2.6

xx <- new.env()
load(system.file("extdata/glmmTMB_example.rda", package = "broom.mixed"), envir = xx)
rf <- glmmTMB::ranef(xx$glmm1, condVar = TRUE)
ret <- as.data.frame(x = rf, stringsAsFactors = FALSE)

# should produce error:

Error in check_dots(...) : unknown arguments: stringsAsFactors

  1. FUN("unknown arguments: ", paste(names(L), collapse = ",")) at utils.R#687
    1. check_dots(...) at methods.R#1164
  2. as.data.frame.ranef.glmmTMB(x = rf, stringsAsFactors = FALSE)
  3. as.data.frame(x = rf, stringsAsFactors = FALSE)

If looks like you can pass an extra arg of action = "message" (or "warning" or "stop"--the default)

ret <- rf %>% as.data.frame(stringsAsFactors = FALSE, action = "message")

Or perhaps, simply don't pass stringsAsFactors argument now.

bbolker commented 3 years ago

This is a good point. It's obviously easiest to drop the stringsAsFactors argument ... I wonder if it will cause any confusion for people who are still on R 3.x but updating their broom.mixed ... ?

Another option would be

          as.data.frame() %>%
          mutate_if(is.factor, as.character) %>%  

which would convert back if necessary ...