Re: [Rd] unloadNamespace (Was: How to unload a dll loaded via library.dynam()?)

From: Berwin A Turlach <berwin_at_maths.uwa.edu.au>
Date: Sat, 21 Feb 2009 01:52:13 +0800

G'day Brian,

On Fri, 20 Feb 2009 11:37:18 +0000 (GMT) Prof Brian Ripley <ripley_at_stats.ox.ac.uk> wrote:

> This was rather a large shift of subject, [...]

Well, yes, from the clean unloading of compiled code to the clean unloading of R code. :-)
Though, I also confirmed that the former is possible on a cooperative OS when library.dynam.unload() is correctly used via an .onUnload() hook.

> Is lazy loading involved?

Yes, the DESCRIPTION file has the default "LazyLoad: yes" entry.

If I set "LazyLoad: no", then both sequences use the new version of the R code immediately.

> If so I have an idea that may or may not be relevant. We do cache in
> memory the lazy-loading database for speed on slow (network-mounted
> or USB drive) file systems. Now the cache is flushed at least if you
> do detach(foo, unload = TRUE) or but I can envisage a set of
> circumstances in which it might not be.

As far as I can tell, "detach(foo, unload=TRUE)" and "unloadNamespace(foo)" behave identical on my machines (while the DESCRIPTION file has "LazyLoad: yes"); the modified R code is only used if either of this command is given (followed by "library(foo)") after the new version of the package was installed.

> So perhaps try detach(foo, unload = TRUE) or not using lazy-loading
> when developing the package?

Unfortunately, the former does not work and although the latter works I am hesitant to use it since:

  1. as I understand it, most packages that use S4 methods need lazy-loading (though the particular package with which I noticed the behaviour does not have S4 methods); and
  2. it seems that these days the DESCRIPTION file is the only way of switching lazy loading on and off and that there is no way of overriding that value. Knowing myself, I would forget changing the DESCRIPTION file back to "LazyLoad: yes" before building the .tar.gz file for distribution (once the package is ready). As it is, I have already to remember to take "-Wall -pedantic" out of the Makevars file in the src/ directory; but I am reminded of that by R CMD check.

Well, thinking a bit more about b), I could probably complicate my Makefile a bit more such that a "make install" first modifies the DESCRIPTION file to "LazyLoad: no" before installing the package to the local library and that "make build" first modifies the DESCRIPTION in the opposite way. But this would still leave concern a).

Cheers,

        Berwin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 20 Feb 2009 - 16:53:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 20 Feb 2009 - 18:30:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive