From ripley at stats.ox.ac.uk  Fri Mar 11 20:07:12 2011
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Fri, 11 Mar 2011 19:07:12 +0000 (GMT)
Subject: [Rd] hook for when R quits
In-Reply-To: <4D7A6F8C.5010904@gmail.com>
References: <AANLkTi=6WYeM-xfqWAxbFNDT83BadEL=mifG26t5ZacN@mail.gmail.com>
	<AANLkTinJPXGWswSpQ-9d8UEzYJW_zU4hAjViNNXWtbUh@mail.gmail.com>
	<AANLkTinRW0h_U_27g95RnkcsAdWJ1-vKzW5YJ3JTJ_f-@mail.gmail.com>
	<4D7A6F8C.5010904@gmail.com>
Message-ID: <alpine.LFD.2.02.1103111905540.22619@gannet.stats.ox.ac.uk>

On Fri, 11 Mar 2011, Duncan Murdoch wrote:

> On 11/03/2011 1:37 PM, Michael Lawrence wrote:
>> Thanks for the suggestion, but I don't think that R finalizes all of its
>> objects when it quits. At least a simple test suggests that on Linux.
>
> Did you use onexit=TRUE?  On Windows that appears to work...

It does work: RODBC makes extensive use of it, for exactly the purpose 
you describe (or rather, the C_level equivalent of 'it').

>
> Duncan Murdoch
>
>> Michael
>> 
>> On Fri, Mar 11, 2011 at 10:19 AM, Jeffrey 
>> Ryan<jeffrey.ryan at lemnica.com>wrote:
>> 
>> >  Take a look at reg.finalizer.  You'd have to create an object
>> >  internally that would persist until R exits - and a related function
>> >  to handle cleanup of course.
>> >
>> >  HTH
>> >  Jeff
>> >
>> >  On Fri, Mar 11, 2011 at 12:08 PM, Michael Lawrence
>> >  <lawrence.michael at gene.com>  wrote:
>> >  >  Hi,
>> >  >
>> >  >  Is there any way that a package can listen for when R quits? The Qt 
>> stuff
>> >  is
>> >  >  hooking into platform-specific event loops and when those die
>> >  unexpectedly
>> >  >  (from the perspective of Qt), it aborts, causing an annoying error
>> >  dialog.
>> >  >  If we could catch when R is killed, we could cleanup, like we do with
>> >  >  .onUnload.
>> >  >
>> >  >  Thanks,
>> >  >  Michael
>> >  >
>> >  >         [[alternative HTML version deleted]]
>> >  >
>> >  >  ______________________________________________
>> >  >  R-devel at r-project.org mailing list
>> >  >  https://stat.ethz.ch/mailman/listinfo/r-devel
>> >  >
>> >
>> >
>> >
>> >  --
>> >  Jeffrey Ryan
>> >  jeffrey.ryan at lemnica.com
>> >
>> >  www.lemnica.com
>> >
>>
>> 	[[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-devel at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-devel
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



[Rd] hook for when R quits
Prof Brian Ripley