Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

lmList gives warnings with tibbles #406

Closed
bbolker opened this Issue Jan 5, 2017 · 6 comments

Comments

Projects
None yet
3 participants
Owner

bbolker commented Jan 5, 2017

"tibbles" are the Hadley Wickham/tidyverse extensions of data frames.

This might not be something we want to worry about, but it would be nice to fix if it's easy:

library(lme4)
library(tibble)

set.seed(101)
dd <- data.frame(y=rnorm(300),
                 x=rnorm(300),
                 f=factor(rep(1:3,100)))
m1 <- lmList(y~x|f,data=dd)
m2 <- lmList(y~x|f,data=as.tbl(dd))
Warning messages:
1: Unknown column '(weights)' 
2: Unknown column '(offset)' 
3: Unknown column '(weights)' 
4: Unknown column '(offset)' 
5: Unknown column '(weights)' 
6: Unknown column '(offset)' 
Contributor

pitakakariki commented Jan 18, 2017

This would probably need to be fixed in stats (or better yet in tibble, but that seems unlikely).

stats::model.offsets uses x$"(offset)". If it used x[["(offset)"]] then tibble wouldn't sulk. Same for stats::model.weights.

Owner

bbolker commented Jun 5, 2017

@mmaechler is this something you would be willing to change in the stats package? This idiom only appears in four places in the code base, that I can see:

(from the root of a recent SVN checkout):

find . -name "*.R" -exec grep -Hn '$"(' {} \;

./src/library/stats/R/lm.R:763: asgn$"(Intercept)" <- NULL
./src/library/stats/R/models.R:528:model.weights <- function(x) x$"(weights)"
./src/library/stats/R/models.R:534: ans <- x$"(offset)"
./src/library/stats/R/models.R:539: else ans <- x$"(offset)"

Owner

bbolker commented Jul 24, 2017

@mmaechler : bump? I could understand if you didn't want to do this/didn't feel it was necessary, but I would argue that asgn[["(Intercept)"]] might be preferable to asgn$"(Intercept)" anyway.

Owner

bbolker commented Jul 24, 2017

It occurs to me that another solution would be to forcibly un-tibble-ify any model frames before working with them.

Owner

bbolker commented Jul 24, 2017

Huh. I can't reproduce this any more (as.tbl is now as.tibble or as_tibble). Session info:

> sessionInfo()
R Under development (unstable) (2017-07-12 r72910)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 14.04.5 LTS

Matrix products: default
BLAS: /usr/local/lib/R/lib/libRblas.so
LAPACK: /usr/local/lib/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_CA.UTF8       LC_NUMERIC=C             
 [3] LC_TIME=en_CA.UTF8        LC_COLLATE=en_CA.UTF8    
 [5] LC_MONETARY=en_CA.UTF8    LC_MESSAGES=en_CA.UTF8   
 [7] LC_PAPER=en_CA.UTF8       LC_NAME=C                
 [9] LC_ADDRESS=C              LC_TELEPHONE=C           
[11] LC_MEASUREMENT=en_CA.UTF8 LC_IDENTIFICATION=C      

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] tibble_1.3.3       nlme_3.1-131       ggplot2_2.2.1.9000 numDeriv_2016.8-1 
[5] lme4_1.1-14        Matrix_1.2-10      rmarkdown_1.6     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.12       knitr_1.16         magrittr_1.5       splines_3.5.0     
 [5] MASS_7.3-47        munsell_0.4.3      colorspace_1.3-2   lattice_0.20-35   
 [9] rlang_0.1.1        minqa_1.2.4        plyr_1.8.4         stringr_1.2.0     
[13] tools_3.5.0        grid_3.5.0         gtable_0.2.0       htmltools_0.3.6   
[17] lazyeval_0.2.0     yaml_2.1.14        rprojroot_1.2      digest_0.6.12     
[21] RColorBrewer_1.1-2 nloptr_1.0.4       codetools_0.2-15   evaluate_0.10.1   
[25] labeling_0.3       stringi_1.1.5      compiler_3.5.0     scales_0.4.1      
[29] backports_1.1.0
Owner

mmaechler commented Jul 25, 2017 edited

I would agree that [["(Intercept)"]] is conceptually a bit better than $..., but no, I was not thinking to change stats just because tibbles didn't behave as they should ...
Good to see the that the tibbleverse has adapted .. ;-)

bbolker closed this Jul 25, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment