Load, detach, re-load anomaly
Asked Answered
T

1

10

I'm attaching, detaching, and re-attaching RODBC and data.table. When I perform this process with these packages in this order, I get the following error:

Error : .onLoad failed in loadNamespace() for 'data.table', details:
  call: address(x)
  error: object 'Caddress' not found

I'm using the latest versions of these packages. This is my initial session info:

R version 3.1.0 (2014-04-10)
Platform: i386-w64-mingw32/i386 (32-bit)

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

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

Example

pkgs <- c('RODBC', 'data.table') # Note, c('data.table', 'RODBC') will work
for (pkg in pkgs) library(pkg, character.only=TRUE)
for (pkg in paste0('package:', pkgs)) detach(pkg, unload=TRUE, character.only=TRUE)
for (pkg in pkgs) library(pkg, character.only=TRUE)
Tensive answered 6/5, 2014 at 15:25 Comment(9)
What if you detach in reverse order? for (pkg in rev(paste0('package:', pkgs))) I don't have all these packages installed so I am unable to try.Geneticist
All other orders of the three packages work, and any 2 combinations of them also work.Tensive
detaching and reloading is never as clean in R as I would like it to be -- long-standing grumble about this aspect of the design. That is, it seems that it's almost impossible in general to engineer code so that attaching + detaching gets you exactly back to the state where you started.Crockery
@BenBolker Is this a problem with the design of R or a problem with the design of the packages? Surely clean attaching + detaching should be possible.Tensive
I can't say for sure. There may be a way to tweak the package so that it attaches/detaches cleanly. What I can say is that it can be very difficult to do this. The two areas where I have had problems are (1) unregistering S4 methods and (2) finalizing Rcpp objects. e.g. github.com/lme4/lme4/issues/35Crockery
And adding to @BenBolker's list of problem areas, there is also no guarantee that even an S3 method will be unregistered when the package that supplies it is detached. (See here for an e.g.) (Not that any of these necessarily explain what's going on in the case you've presented above.)Calico
If you just do: require(RODBC); require(data.table); pkgs <- c('RODBC','data.table'); for (pkg in paste0('package:', pkgs)) detach(pkg, unload=TRUE, character.only=TRUE); require(RODBC); require(data.table), this also reproduces the error - without a third package.Oneill
@Arun, thanks. I thought I had tried that, but apparently not.Tensive
Filed #5671.Oneill
O
3

This is now fixed in commit 1332 of v1.9.3. From NEWS:

Added a .onUnload method to unload data.table's shared object properly. Since the name of the shared object is 'datatable.so' and not 'data.table.so', 'detach' fails to unload correctly. This was the reason for the issue reported here on SO. Closes #474. Thanks to Matthew Plourde for reporting.

Oneill answered 3/8, 2014 at 21:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.