From Hadley C best practices :
As with C ++, whenever you use C code in your package, you must unload the DLL when the package is unloaded:
.onUnload <- function (libpath) { library.dynam.unload("mypackage", libpath) }
Writing R-extensions , on the other hand, doesn't even mention it. I see how it would be politely to unload the DLL, but it seems to me that there are some strange problems with loaded / unloaded / reloaded packages (see the example below). In addition, there are some references that suggest that unloading is not required. From ?library.dynam :
Please note that regardless of whether it is possible to unload the DLL and then reload the corrected version of the same file, it depends on the OS: see the section βHelp value for dyn.unload.
although this should not affect objects that are not modified. Then there is this comment from Brian Ripley in R-devel :
Having said all this, my experience is that unloading the DLL often does not help if you need to load it again (and that is why, for example, tcltk does not unload the DLL).
So is it acceptable to leave the loaded C libraries? I would prefer not to delve into what is happening, as it happens below (it was not before I started unloading the libraries).
R version 3.1.1 (2014-07-10) Platform: x86_64-apple-darwin13.1.0 (64-bit) > library(alike)
All warnings are related to alike features. alike did not use to upload its dynamic libraries, and the above errors did not occur. After I unloaded, the errors started. Please note that data.table 1.9.2 does not unload its DLLs, although other packages that also do not unload DLLs did not cause such problems. data.table 1.9.4 works fine.
c r dll packages
BrodieG Nov 01 '14 at 18:50 2014-11-01 18:50
source share