I just found out that an .onLoad() function such as this stylized one (where I just renamed some identifiers) .onLoad <- function(lib, pkg) { require(zoo, quiet=TRUE, warn.conflicts=FALSE) library.dynam("foolib", pkg, lib ) if (.Platform$OS.type != "windows") { initSomeServices() } if (.Platform$OS.type != "windows") { on.exit(closeSomeServices()) } } actually triggers a call of 'closeSomeServices()'. I am probably misunderstanding something here -- but I thought on.exit() would only be called on, well, exit ? Dirk -- Hell, there are no rules here - we're trying to accomplish something. -- Thomas A. Edison
On 1/16/2007 4:02 PM, Dirk Eddelbuettel wrote:> I just found out that an .onLoad() function such as this stylized one (where > I just renamed some identifiers) > > > .onLoad <- function(lib, pkg) { > require(zoo, quiet=TRUE, warn.conflicts=FALSE) > library.dynam("foolib", pkg, lib ) > if (.Platform$OS.type != "windows") { > initSomeServices() > } > if (.Platform$OS.type != "windows") { > on.exit(closeSomeServices()) > } > } > > actually triggers a call of 'closeSomeServices()'. I am probably > misunderstanding something here -- but I thought on.exit() would only be > called on, well, exit ?It's the exit from the function, not the exit from the package (which isn't really all that well defined -- do you mean unloading, exit from R, detaching?? It's not very easy to have something be guaranteed to execute "when you're done". The RODBC package does it using an external pointer, which has a hook that is called when R shuts down. If it's good enough to execute on unloading but skip execution on shutdown, then .onUnload is available. Duncan Murdoch
on.exit() applies to the function where it was called, i.e. closeSomeServices() is called when .onLoad() exits, or whatever function it is defined in. You're looking for .onUnload(). Make sure to read the help for details. Cheers Henrik On 1/17/07, Dirk Eddelbuettel <edd at debian.org> wrote:> > I just found out that an .onLoad() function such as this stylized one (where > I just renamed some identifiers) > > > .onLoad <- function(lib, pkg) { > require(zoo, quiet=TRUE, warn.conflicts=FALSE) > library.dynam("foolib", pkg, lib ) > if (.Platform$OS.type != "windows") { > initSomeServices() > } > if (.Platform$OS.type != "windows") { > on.exit(closeSomeServices()) > } > } > > actually triggers a call of 'closeSomeServices()'. I am probably > misunderstanding something here -- but I thought on.exit() would only be > called on, well, exit ? > > Dirk > > -- > Hell, there are no rules here - we're trying to accomplish something. > -- Thomas A. Edison > > ______________________________________________ > R-devel at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >