Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dbplyr itself cannot be loaded #779

Closed
CLRafaelR opened this issue Feb 12, 2022 · 21 comments
Closed

dbplyr itself cannot be loaded #779

CLRafaelR opened this issue Feb 12, 2022 · 21 comments

Comments

@CLRafaelR
Copy link

@CLRafaelR CLRafaelR commented Feb 12, 2022

I've successfully installed dbplyr but cannot load it using library() due to the error: error: error in contained classes ("character") for class “ident”; class definition removed from ‘dbplyr’. The very same error also causes the installation failure and loading failure of the packages that depend on dbplyr, as a couple of posts (#619, #688, https://community.rstudio.com/t/tidyverse-error-failed-to-load/105345) has already reported for the last few years.

I installed dbplyr 2.1.1 from CRAN and faced the error. I also remove the dbplyr from CRAN, and reinstalled the package by devtools::install_github("tidyverse/dbplyr"); but the error persists. Is there any way to resolve the problem from the user side, or would you please fix this?

Sys.setenv("_R_TRACE_LOADNAMESPACE_" = 4)

Loading dbplyr fails

"dbplyr" %in% installed.packages() # TRUE, which means that the package has already been installed successfully
library(dbplyr)
- loadingdbplyr-- processing imports fordbplyr-- done processing imports fordbplyr-- loading code fordbplyr-- loading code fordbplyr-- registerS3methods fordbplyr-- done registerS3methods fordbplyr-- running .onLoad fordbplyrError in completeSubclasses(classDef2, class1, obj, where) : 
  trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots
Error: package or namespace load failed fordbplyr:
 .onLoad failed in loadNamespace() for 'dbplyr', details:
  call: setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where)
  error: error in contained classes ("character") for classident”; class definition removed fromdbplyr

Loading tidyverse fails, since tidyverse depends on dbplyr

"tidyverse" %in% installed.packages() # TRUE
library(tidyverse)
- loadingtidyverse-- processing imports fortidyverse- loadingdbplyr-- processing imports fordbplyr-- done processing imports fordbplyr-- loading code fordbplyr-- loading code fordbplyr-- registerS3methods fordbplyr-- done registerS3methods fordbplyr-- running .onLoad fordbplyrError in completeSubclasses(classDef2, class1, obj, where) : 
  trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots
Error: package or namespace load failed fortidyverse:
 .onLoad failed in loadNamespace() for 'dbplyr', details:
  call: setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where)
  error: error in contained classes ("character") for classident”; class definition removed fromdbplyr

SessionInfo

sessionInfo()
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=Japanese_Japan.932  LC_CTYPE=Japanese_Japan.932   
[3] LC_MONETARY=Japanese_Japan.932 LC_NUMERIC=C                  
[5] LC_TIME=Japanese_Japan.932    

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

other attached packages:
[1] furrr_0.2.3   future_1.23.0

loaded via a namespace (and not attached):
 [1] matrixStats_0.61.0   fs_1.5.2             usethis_2.1.5       
 [4] lubridate_1.8.0      devtools_2.4.3       rprojroot_2.0.2     
 [7] rstan_2.26.6         tools_4.1.2          backports_1.4.1     
[10] utf8_1.2.2           R6_2.5.1             DBI_1.1.2           
[13] colorspace_2.0-2     withr_2.4.3          tidyselect_1.1.1    
[16] gridExtra_2.3        prettyunits_1.1.1    processx_3.5.2      
[19] Brobdingnag_1.2-7    curl_4.3.2           compiler_4.1.2      
[22] cli_3.1.1            desc_1.4.0           scales_1.1.1        
[25] mvtnorm_1.1-3        callr_3.7.0          stringr_1.4.0       
[28] digest_0.6.29        StanHeaders_2.26.6   rmarkdown_2.11      
[31] rethinking_2.21      extraDistr_1.9.1     pkgconfig_2.0.3     
[34] htmltools_0.5.2      parallelly_1.30.0    sessioninfo_1.2.2   
[37] fastmap_1.1.0        rlang_1.0.1          rstudioapi_0.13     
[40] shape_1.4.6          generics_0.1.2       jsonlite_1.7.3      
[43] dplyr_1.0.8          inline_0.3.19        magrittr_2.0.2      
[46] loo_2.4.1            Matrix_1.4-0         Rcpp_1.0.8          
[49] munsell_0.5.0        fansi_1.0.2          lifecycle_1.0.1     
[52] stringi_1.7.6        yaml_2.2.2           MASS_7.3-55         
[55] brio_1.1.3           pkgbuild_1.3.1       grid_4.1.2          
[58] parallel_4.1.2       listenv_0.8.0        crayon_1.4.2        
[61] lattice_0.20-45      knitr_1.37           ps_1.6.0            
[64] pillar_1.7.0         codetools_0.2-18     stats4_4.1.2        
[67] pkgload_1.2.4        glue_1.6.1           evaluate_0.14       
[70] V8_4.1.0             remotes_2.4.2        RcppParallel_5.1.5  
[73] vctrs_0.3.8          testthat_3.1.2       gtable_0.3.0        
[76] purrr_0.3.4          tidyr_1.2.0          assertthat_0.2.1    
[79] cachem_1.0.6         ggplot2_3.3.5        xfun_0.29           
[82] broom_0.7.12         coda_0.19-4          tibble_3.1.6        
[85] memoise_2.0.1        globals_0.14.0       ellipsis_0.3.2      
[88] cmdstanr_0.4.0       bridgesampling_1.1-2
@CLRafaelR
Copy link
Author

@CLRafaelR CLRafaelR commented Feb 14, 2022

UPDATE

I found that dbplyr (and therefore other packages that depend on it, e.g. tidyverse) can be successfully loaded into RGui.exe using library(). Admin mode is not required to successfully run library(dbplyr) using RGui.exe. However, the load of dbplyr and its related packages still fail when I use R from RStudio (RStudio 2021.09.0 Build 341). Running find.package("dbplyr") on both Rgui.exe and RStudio points the same path to the library, "C:/Users/[my username]/Documents/R/win-library/4.1/dbplyr"

@Sz-Tim
Copy link

@Sz-Tim Sz-Tim commented Feb 22, 2022

I get a similar error when using %dopar% in foreach, but only in parallel (i.e., not with %do%) and only when one of the functions uses a .brmsfit object created with the package brms.

The message printed to the console by foreach is:

Error in { :
task 1 failed - "package or namespace load failed for 'dbplyr':
.onLoad failed in loadNamespace() for 'dbplyr', details:
call: setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where)
error: error in contained classes ("character") for class "ident"; class definition removed from 'dbplyr'"

And if I set the workers to log their output, the error is:

Error in completeSubclasses(classDef2, class1, obj, where) :
trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots

@CLRafaelR
Copy link
Author

@CLRafaelR CLRafaelR commented Feb 22, 2022

@Sz-Tim

Could you tell us your situation in more detail, since foreach does not seem to depend on dbplyr (see the dependency of foreach here)?

  • How do you load foreach package? Do you use library()?
    • If you use library(), do you always successfully load foreach using library()? (i.e. Does library("foreach") works always successfully?)
    • If library("foreach") works fine, which do you use to execute the command library("foreach"), RStudio or Rgui.exe?
  • Could you tell us the version of the following software/packages you use?
    • R itself
    • RStudio
    • dbplyr
    • foreach
    • rlang (I suspect that dbplyr's load failure started in my environment after updating rlang, though I have no proof of this)

@Sz-Tim
Copy link

@Sz-Tim Sz-Tim commented Feb 22, 2022

@CLRafaelR

I'm using foreach to run simulations in parallel, and the simulations require tidyverse functions and draw on regressions fitted in brms. I can try to put together a reproducible example, but it will take a little time. The foreach call is:

library(doSNOW); library(foreach)
cl <- makeCluster(12, outfile="temp\\sim_out.txt")
registerDoSNOW(cl)
out.ls <- foreach(i=1:nrow(grid.i), .combine="c", 
                  .packages=c("tidyverse", "brms", "glue", "lubridate") %dopar% {
  ...
}

If I run in series with %do% instead of in parallel with %dopar%, everything works fine. I've tried loading the packages in different orders, explicitly calling them with library() inside the foreach() {...} expression, and loading dplyr directly, but the outcome is always the same.

If I use frequentist regressions (i.e., if I do not use anything from the brms package), there is no error. It's some interaction between brms, dbplyr, and something behind the scenes that foreach does with parallelization. Registering the cluster with doParallel instead of doSNOW has no impact.

This did start about a week ago when I unfortunately updated many packages, which makes it harder to track down exactly which combination is causing the error.


To answer your questions:

  1. I load foreach with library(), and as I said, I've tried loading within foreach using the .packages argument and directly calling library()
    i. I do not get any errors upon loading packages. This is only happening within the parallelized workers.
    ii. This happens within RStudio, both directly from the console and running the script as a local job.
  2. Here is my system info:
> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

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

other attached packages:
 [1] doSNOW_1.0.20    snow_0.4-4       iterators_1.0.14 foreach_1.5.2    readxl_1.3.1     brms_2.16.3      Rcpp_1.0.8      
 [8] lme4_1.1-28      Matrix_1.4-0     glue_1.6.1       sf_1.0-6         forcats_0.5.1    stringr_1.4.0    dplyr_1.0.8     
[15] purrr_0.3.4      readr_2.1.2      tidyr_1.2.0      tibble_3.1.6     ggplot2_3.3.5    tidyverse_1.3.1  lubridate_1.8.0 
[22] raster_3.5-15    sp_1.4-6        

loaded via a namespace (and not attached):
  [1] backports_1.4.1      plyr_1.8.6           igraph_1.2.11        splines_4.1.1        crosstalk_1.2.0      usethis_2.1.5       
  [7] rstantools_2.1.1     inline_0.3.19        digest_0.6.29        htmltools_0.5.2      rsconnect_0.8.25     fansi_1.0.2         
 [13] memoise_2.0.1        magrittr_2.0.2       checkmate_2.0.0      remotes_2.4.2        tzdb_0.2.0           modelr_0.1.8        
 [19] RcppParallel_5.1.5   matrixStats_0.61.0   vroom_1.5.7          xts_0.12.1           prettyunits_1.1.1    colorspace_2.0-3    
 [25] rvest_1.0.2          haven_2.4.3          xfun_0.29            rgdal_1.5-28         callr_3.7.0          crayon_1.5.0        
 [31] jsonlite_1.7.3       zoo_1.8-9            gtable_0.3.0         distributional_0.3.0 pkgbuild_1.3.1       rstan_2.21.3        
 [37] abind_1.4-5          scales_1.1.1         mvtnorm_1.1-3        DBI_1.1.2            miniUI_0.1.1.1       xtable_1.8-4        
 [43] units_0.8-0          bit_4.0.4            proxy_0.4-26         StanHeaders_2.21.0-7 stats4_4.1.1         DT_0.20             
 [49] htmlwidgets_1.5.4    httr_1.4.2           threejs_0.3.3        wk_0.6.0             posterior_1.2.0      ellipsis_0.3.2      
 [55] pkgconfig_2.0.3      loo_2.4.1            farver_2.1.0         dbplyr_2.1.1         utf8_1.2.2           tidyselect_1.1.2    
 [61] rlang_1.0.1          reshape2_1.4.4       later_1.3.0          cachem_1.0.6         munsell_0.5.0        cellranger_1.1.0    
 [67] tools_4.1.1          cli_3.1.1            generics_0.1.2       devtools_2.4.3       broom_0.7.12         ggridges_0.5.3      
 [73] evaluate_0.15        fastmap_1.1.0        yaml_2.2.2           processx_3.5.2       knitr_1.37           bit64_4.0.5         
 [79] fs_1.5.2             s2_1.0.7             nlme_3.1-152         projpred_2.0.2       mime_0.12            xml2_1.3.3          
 [85] brio_1.1.3           compiler_4.1.1       bayesplot_1.8.1      shinythemes_1.2.0    rstudioapi_0.13      gamm4_0.2-6         
 [91] testthat_3.1.2       e1071_1.7-9          reprex_2.0.1         stringi_1.7.6        ps_1.6.0             desc_1.4.0          
 [97] Brobdingnag_1.2-7    lattice_0.20-44      classInt_0.4-3       nloptr_2.0.0         markdown_1.1         shinyjs_2.1.0       
[103] tensorA_0.36.2       vctrs_0.3.8          pillar_1.7.0         lifecycle_1.0.1      bridgesampling_1.1-2 httpuv_1.6.5        
[109] R6_2.5.1             promises_1.2.0.1     KernSmooth_2.23-20   gridExtra_2.3        sessioninfo_1.2.2    codetools_0.2-18    
[115] pkgload_1.2.4        boot_1.3-28          colourpicker_1.1.1   MASS_7.3-54          gtools_3.9.2         assertthat_0.2.1    
[121] rprojroot_2.0.2      withr_2.4.3          shinystan_2.5.0      mgcv_1.8-36          parallel_4.1.1       hms_1.1.1           
[127] terra_1.5-21         grid_4.1.1           coda_0.19-4          class_7.3-19         minqa_1.2.4          rmarkdown_2.11      
[133] shiny_1.7.1          base64enc_0.1-3      dygraphs_1.1.1.6   

I'm using RStudio 2021.09.0+351

@padpadpadpad
Copy link

@padpadpadpad padpadpadpad commented Feb 25, 2022

Hi all

I get a similar error when running loading brms in before tidyverse.

library(brms)
library(tidyverse)
Error in completeSubclasses(classDef2, class1, obj, where) : 
  trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots
Error: package or namespace load failed for ‘tidyverse’:
 .onLoad failed in loadNamespace() for 'dbplyr', details:
  call: setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where)
  error: error in contained classes ("character") for class “ident”; class definition removed from ‘dbplyr’

But the other way around works fine.

library(tidyverse)
library(brms)

R version: 4.1.2
RStudio version: RStudio 2022.02.0+443 "Prairie Trillium" Release (9f7969398b90468440a501cf065295d9050bb776, 2022-02-16) for macOS
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) QtWebEngine/5.12.10 Chrome/69.0.3497.128 Safari/537.36
brms version: 2.16.3
tidyverse version: 1.3.1
dbplyr version: 2.1.1

@Sz-Tim
Copy link

@Sz-Tim Sz-Tim commented Mar 9, 2022

Reversing the order doesn't stop the error for me, but I did find a sequence that works.

Everything runs successfully if I start the function (that is being parallelized) with:

library(brms); library(Matrix); library(tidyverse)

I'm currently using parallel::parLapply() instead of foreach.

> sessionInfo()
R version 4.1.1 (2021-08-10)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252    LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                            LC_TIME=English_United Kingdom.1252    

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

other attached packages:
 [1] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.8     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0     tibble_3.1.6   
 [8] ggplot2_3.3.5   tidyverse_1.3.1 Matrix_1.4-0    brms_2.16.3     Rcpp_1.0.8     

loaded via a namespace (and not attached):
  [1] minqa_1.2.4          colorspace_2.0-3     ellipsis_0.3.2       ggridges_0.5.3       rsconnect_0.8.25    
  [6] markdown_1.1         fs_1.5.2             base64enc_0.1-3      rstudioapi_0.13      farver_2.1.0        
 [11] rstan_2.21.3         DT_0.20              fansi_1.0.2          mvtnorm_1.1-3        lubridate_1.8.0     
 [16] xml2_1.3.3           bridgesampling_1.1-2 codetools_0.2-18     splines_4.1.1        shinythemes_1.2.0   
 [21] bayesplot_1.8.1      projpred_2.0.2       jsonlite_1.7.3       nloptr_2.0.0         broom_0.7.12        
 [26] dbplyr_2.1.1         shiny_1.7.1          compiler_4.1.1       httr_1.4.2           backports_1.4.1     
 [31] assertthat_0.2.1     fastmap_1.1.0        cli_3.1.1            later_1.3.0          htmltools_0.5.2     
 [36] prettyunits_1.1.1    tools_4.1.1          igraph_1.2.11        coda_0.19-4          gtable_0.3.0        
 [41] glue_1.6.1           reshape2_1.4.4       posterior_1.2.0      cellranger_1.1.0     vctrs_0.3.8         
 [46] nlme_3.1-152         crosstalk_1.2.0      tensorA_0.36.2       ps_1.6.0             rvest_1.0.2         
 [51] lme4_1.1-28          mime_0.12            miniUI_0.1.1.1       lifecycle_1.0.1      gtools_3.9.2        
 [56] MASS_7.3-54          zoo_1.8-9            scales_1.1.1         colourpicker_1.1.1   hms_1.1.1           
 [61] promises_1.2.0.1     Brobdingnag_1.2-7    parallel_4.1.1       inline_0.3.19        shinystan_2.5.0     
 [66] gamm4_0.2-6          gridExtra_2.3        loo_2.4.1            StanHeaders_2.21.0-7 stringi_1.7.6       
 [71] dygraphs_1.1.1.6     checkmate_2.0.0      boot_1.3-28          pkgbuild_1.3.1       rlang_1.0.1         
 [76] pkgconfig_2.0.3      matrixStats_0.61.0   distributional_0.3.0 lattice_0.20-44      rstantools_2.1.1    
 [81] htmlwidgets_1.5.4    processx_3.5.2       tidyselect_1.1.2     plyr_1.8.6           magrittr_2.0.2      
 [86] R6_2.5.1             generics_0.1.2       DBI_1.1.2            withr_2.4.3          pillar_1.7.0        
 [91] haven_2.4.3          mgcv_1.8-36          xts_0.12.1           abind_1.4-5          modelr_0.1.8        
 [96] crayon_1.5.0         utf8_1.2.2           tzdb_0.2.0           grid_4.1.1           readxl_1.3.1        
[101] callr_3.7.0          threejs_0.3.3        reprex_2.0.1         digest_0.6.29        xtable_1.8-4        
[106] httpuv_1.6.5         RcppParallel_5.1.5   stats4_4.1.1         munsell_0.5.0        shinyjs_2.1.0    

@isaactpetersen
Copy link

@isaactpetersen isaactpetersen commented Mar 13, 2022

I receive the error as well. I'm on a Linux cluster and can't update R to a more recent version.

I receive the error when trying to load {tidyverse}:

> library("tidyverse")
Error in completeSubclasses(classDef2, class1, obj, where) : 
  trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots
Error: package or namespace load failed for ‘tidyverse’:
 .onLoad failed in loadNamespace() for 'dbplyr', details:
  call: setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where)
  error: error in contained classes ("character") for class “ident”; class definition removed from ‘dbplyr’
Execution halted

Here are the versions of packages I have installed:

tidyverse: 1.3.1
dbplyr: 2.1.1
Matrix: 1.4-0
renv: 0.15.4

Here's my sessionInfo():

R version 4.0.5 (2021-03-31)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: CentOS Linux 7 (Core)

Matrix products: default
BLAS/LAPACK: /opt/ssoft/apps/2021.1/linux-centos7-skylake_avx512/gcc-9.3.0/intel-mkl-2020.4.304-glgoamq/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so

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

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

loaded via a namespace (and not attached):
  [1] nlme_3.1-155         matrixStats_0.61.0   xts_0.12.1          
  [4] lubridate_1.8.0      threejs_0.3.3        rstan_2.21.3        
  [7] tensorA_0.36.2       tools_4.0.5          backports_1.4.1     
 [10] utf8_1.2.2           R6_2.5.1             DT_0.21             
 [13] DBI_1.1.2            colorspace_2.0-3     tidyselect_1.1.2    
 [16] gridExtra_2.3        prettyunits_1.1.1    processx_3.5.2      
 [19] Brobdingnag_1.2-7    emmeans_1.7.2        compiler_4.0.5      
 [22] cli_3.2.0            shinyjs_2.1.0        sandwich_3.0-1      
 [25] colourpicker_1.1.1   posterior_1.2.0      scales_1.1.1        
 [28] dygraphs_1.1.1.6     checkmate_2.0.0      brms_2.16.3         
 [31] mvtnorm_1.1-3        ggridges_0.5.3       callr_3.7.0         
 [34] stringr_1.4.0        digest_0.6.29        StanHeaders_2.21.0-7
 [37] minqa_1.2.4          base64enc_0.1-3      pkgconfig_2.0.3     
 [40] htmltools_0.5.2      fastmap_1.1.0        htmlwidgets_1.5.4   
 [43] rlang_1.0.1          shiny_1.7.1          farver_2.1.0        
 [46] generics_0.1.2       zoo_1.8-9            crosstalk_1.2.0     
 [49] gtools_3.9.2         dplyr_1.0.8          distributional_0.3.0
 [52] inline_0.3.19        magrittr_2.0.2       loo_2.4.1           
 [55] bayesplot_1.8.1      Matrix_1.4-0         Rcpp_1.0.8          
 [58] munsell_0.5.0        fansi_1.0.2          abind_1.4-5         
 [61] lifecycle_1.0.1      stringi_1.7.6        multcomp_1.4-18     
 [64] MASS_7.3-55          pkgbuild_1.3.1       plyr_1.8.6          
 [67] grid_4.0.5           parallel_4.0.5       promises_1.2.0.1    
 [70] crayon_1.5.0         miniUI_0.1.1.1       lattice_0.20-45     
 [73] splines_4.0.5        ps_1.6.0             pillar_1.7.0        
 [76] igraph_1.2.11        boot_1.3-28          markdown_1.1        
 [79] estimability_1.3     shinystan_2.6.0      reshape2_1.4.4      
 [82] codetools_0.2-18     stats4_4.0.5         rstantools_2.1.1    
 [85] glue_1.6.2           renv_0.15.4          RcppParallel_5.1.5  
 [88] vctrs_0.3.8          httpuv_1.6.5         gtable_0.3.0        
 [91] purrr_0.3.4          assertthat_0.2.1     ggplot2_3.3.5       
 [94] mime_0.12            xtable_1.8-4         coda_0.19-4         
 [97] later_1.3.0          survival_3.3-0       tibble_3.1.6        
[100] shinythemes_1.2.0    TH.data_1.1-0        ellipsis_0.3.2      
[103] bridgesampling_1.1-2

@netique
Copy link

@netique netique commented Mar 14, 2022

Interestingly enough, when I library(dbplyr) and then library(tidyverse), it works well. Another point is that in RStudio, when I load tidyverse and get the ominous error, typing dbplyr:: immediately throws

Error in completeSubclasses(classDef2, class1, obj, where) : 
  trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots

Also, failed tidyverse load does not put any tidyverse package on search path.

But when I create a completely new project, everything works.

EDIT: when a clear the history, it works even in the project that it previously failed in...
EDIT2: The issue seems to lie in previously loading brms. Any tidyverse or dbplyr library call then results in the error.

session_info.txt

Note the DLL MD5 mismatch for RcppParallel.
EDIT: I have reinstalled RcppParallel from source, no DLL mismatch is present, but the issue persist.

@netique
Copy link

@netique netique commented Mar 14, 2022

FYI, there is full loadNamespace trace (using _R_TRACE_LOADNAMESPACE_ = 4):

out.txt

@proshano

This comment was marked as outdated.

@netique
Copy link

@netique netique commented Mar 20, 2022

@proshano Note the rstan, bridgesampler and others, such as emmeans loaded via namespace. The issue have to be caused by some method registration conflict about Stan-related packages and tidyverse/dbplyr.

@netique
Copy link

@netique netique commented Mar 25, 2022

Don`t want to be annoying, but is anyone actively solving this? It seems like a big deal not to be able to load a package...

@mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Mar 28, 2022

I now managed to reproduce the issue.

library(bridgesampling)
library(dbplyr)

I tracked the issue down to methods::completeSubclasses():

for (i in seq_along(contains)) {
      obji <- contains[[i]]
      cli <- contains[[i]]@superClass
      cliDef <- getClassDef(cli, package = packageSlot(obji))
      subcl <- cliDef@subclasses[[class2]]
      if (is.null(subcl)) {
        exti <- extends(classDef2, cliDef, fullInfo = TRUE)
        if (identical(exti, FALSE) || (is(exti, "SClassExtension") && 
          exti@distance > 1L && classDef@className == 
          exti@by)) 
          setIs(class2, cli, extensionObject = obji, 
            doComplete = FALSE, where = where)
      }
    }

The 4th element of contains is the class index of the Matrix package

cli
#> [1] "index"
#> attr(,"package")
#> [1] "Matrix"

The line getClassDef(cli, package = packageSlot(obji)) returns

  • NULL if bridgesampling is loaded but Matrix is not.
  • and returns
Extended class definition ( "ClassUnionRepresentation" )
Virtual Class "index" [package "Matrix"]
.. .

if neither bridgesampling nor Matrix are loaded or both are loaded.

@mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Mar 28, 2022

This can be further simplified to creating a package with

#'@importFrom Brobdingnag brob
#'@importFrom Matrix nearPD
f <- function(x) {}

And then I found that Brobdingnag defines index as a Union

setClassUnion("index", members =  c("numeric", "logical", "character"))

which seems to cause the issue.

The Matrix package has the same definition for index but it also exports the Class in the Namespace

Edit: Exporting actually does not help...

@hadley Can you help here?

@hadley
Copy link
Member

@hadley hadley commented Mar 28, 2022

@mgirlich what's the connection to dbplyr here? I assume it must be something to do with the setOldClass() calls on .onLoad():

methods::setOldClass(c("ident_q", "ident", "character"), ident_q())
methods::setOldClass(c("ident", "character"), ident())
methods::setOldClass(c("sql", "character"), sql())

But there's must be something else going on because this works fine:

library(methods)

setClassUnion("index", c("numeric", "logical", "character"))
setOldClass(c("ident", "character"), dbplyr::ident())

Created on 2022-03-28 by the reprex package (v2.0.1)

Unfortunately this sort of problem is very hard to debug as its likely to be a bug either in S4 or in the way that bridgesampling, dbplyr, or one of their dependencies is using it.

@mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Mar 28, 2022

I think it is a bug in S4 and/or an issue of bridgesampling.

My picture what happens is:

  • dbplyr calls setOldClass(c("ident", "character"), dbplyr::ident())
  • Somewhere deep down this calls methods::completeSubclasses()

There it iterates over the S4 classes that have "character" in their class definition. One of these classes is index. Now

  • if nothing or Matrix is loaded: the index class is found as part of Matrix
  • if bridgesampling is loaded but Matrix not: the index class is found as part of bridgesampling

Then it tries to find class definition of index but can't find it in the 2nd case.
The issue seems to vanish (at least for me) if bridgesampling does not define index itself but rather re-exports it from Matrix. This should be the easiest fix. Do you think this makes sense?

@hadley
Copy link
Member

@hadley hadley commented Mar 28, 2022

How can "if bridgesampling is loaded but Matrix not" happen? bridgesampling imports Matrix in the DESCRIPTION and specficially imports matrix::nearPD() in the NAMESPACE. Did you mean "attached" rather than loaded? i.e. the problem is that something deep in completeSubclasses() is relying on the search path?

And why is the briddgesampling the root cause? It doesn't seem to define any S4 classes of its own? .... Oh it's just the order in which it loads namespaces. So an even simpler reprex is:

requireNamespace("Brobdingnag")
#> Loading required namespace: Brobdingnag
requireNamespace("Matrix")
#> Loading required namespace: Matrix
requireNamespace("dbplyr")
#> Loading required namespace: dbplyr
#> Error in completeSubclasses(classDef2, class1, obj, where) : 
#>   trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots

Created on 2022-03-28 by the reprex package (v2.0.1)

@hadley
Copy link
Member

@hadley hadley commented Mar 28, 2022

Even simpler:

requireNamespace("Brobdingnag")
#> Loading required namespace: Brobdingnag
requireNamespace("Matrix")
#> Loading required namespace: Matrix
methods::setOldClass(c("ident", "character"))
#> Error in completeSubclasses(classDef2, class1, obj, where) : 
#>   trying to get slot "subclasses" from an object of a basic class ("NULL") with no slots
#> Error in setClass(cl, contains = c(prevClass, "VIRTUAL"), where = where): error in contained classes ("character") for class "ident"; class definition removed from '.GlobalEnv'

Created on 2022-03-28 by the reprex package (v2.0.1)

So it seems almost certain that the problem lies in Brobdingnag

@hadley
Copy link
Member

@hadley hadley commented Mar 28, 2022

(Oh I think you just accidentally wrote bridgesampling above, when you meant Brobdingnag)
...
(Oh yeah, and my reprex does the same thing your minimal package reprex does)

@mgirlich
Copy link
Collaborator

@mgirlich mgirlich commented Mar 29, 2022

The problem is fixed in the dev version of Brobdingnag. Install it with devtools::install_github("RobinHankin/Brobdingnag") and you should have no more issues loading dbplyr.

@hadley
Copy link
Member

@hadley hadley commented Mar 30, 2022

I pinged Michael Lawrence about this and he also pushed a fix to R-devel: wch/r-source@3d97199

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants