Skip to content

data.table fails with emmeans objects #6874

@matschmitz

Description

@matschmitz

This issue is fairly recent and used to work perfectly fine in the past. It may be partly related to the R version.

Using data.table with emmeans objects now produces errors, while equivalent operations with base data.frame succeed.

Reproducible Example:

library(data.table) # v1.17.0
library(emmeans) # v1.10.7

mdl <- lm(dist ~ speed, data = cars)
em_res <- emmeans(mdl, ~ 1)

data.frame(em_res)
#        X1 emmean       SE df lower.CL upper.CL
# 1 overall  42.98 2.175002 48 38.60687 47.35313

data.table(em_res)
# Error in setDT(ans, key = key) : LENGTH or similar applied to S4 object

as.data.table(em_res)
# Error: C stack usage 15924944 is too close to the limit

Session Info:

R version 4.4.3 (2025-02-28 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  
[2] LC_CTYPE=English_United States.utf8    
[3] LC_MONETARY=English_United States.utf8 
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United States.utf8    

time zone: Europe/Berlin
tzcode source: internal

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

other attached packages:
[1] emmeans_1.10.7-100003 data.table_1.17.0    

loaded via a namespace (and not attached):
 [1] codetools_0.2-20   multcomp_1.4-28    Matrix_1.7-3       
 [4] lattice_0.22-6     coda_0.19-4.1      TH.data_1.1-3      
 [7] splines_4.4.3      estimability_1.5.1 zoo_1.8-13         
[10] mvtnorm_1.3-3      xtable_1.8-4       grid_4.4.3        
[13] sandwich_3.1-1     compiler_4.4.3     tools_4.4.3       
[16] survival_3.8-3     MASS_7.3-65       

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions