[Rd] Should R Packages Unload Dynamic Libraries When They Unload?

brodie gaslam brodie.gaslam at yahoo.com
Tue Nov 11 15:39:15 CET 2014



>From Hadley's C best practices (http://r-pkgs.had.co.nz/src.html#c-best-practices):

> Like with C++, whenever you use C code in your package, you should 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 this (AFAIK). I can see how it would be polite to unload the dlls, but doing so seems to cause some weird problems for me with packages that are loaded/unloaded/reloaded. Additionally, there are some mentions that suggest maybe unloading isn't required. From ?library.dynam:

> Note that whether or not it is possible to unload a DLL and then reload a revised version of the same file is OS-dependent: see the ‘Value’ section of the help for dyn.unload.

though this shouldn't affect objects that are not modified. Then there is this comment from Brian Ripley in R-devel (https://stat.ethz.ch/pipermail/r-devel/2010-November/059062.html):

> Having said all that, my experience is that unloading the DLL often does not help if you need to load it again (and that is why e.g. tcltk does not unload its DLL).

Is it acceptable for packages to leave the C libraries loaded when they are unloaded?


I'm on R 3.1.1 on a Mac OS X, though this question is not specific to my system.


I originally asked this on SO (http://stackoverflow.com/questions/26691878/must-r-packages-unload-dynamic-libraries-when-they-unload), but got crickets.
	[[alternative HTML version deleted]]



More information about the R-devel mailing list