Re: [Rd] hook for when R quits

From: Duncan Murdoch <murdoch.duncan_at_gmail.com>
Date: Fri, 11 Mar 2011 16:05:37 -0500

On 11/03/2011 3:11 PM, Henrik Bengtsson wrote:
> On Fri, Mar 11, 2011 at 11:07 AM, Prof Brian Ripley
> <ripley_at_stats.ox.ac.uk> wrote:
> > 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...

>

> Agree - here an object finalizer is more appropriate (different from
> an end-of-session hook).
>

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

> In help(reg.finalizer) it says:
>

> 'onexit': logical: should the finalizer be run if the object is
> still uncollected at the end of the R session?
>

> What environments, objects, search path etc are available when the
> finalizer is called this way when R exits? Is safe to always add
> 'onexit=TRUE' (which now defaults to FALSE), or should I expect an
> "exceptional" R system that the finalizer needs to account for?

To be very conservative, I would assume that nothing in R is available other than things that are stored in that environment. That's probably not true, but it would be safe. This mechanism is for finalizing things that R doesn't know about.

If you want to be less conservative, then you could look at the source code: currently R_RunExitFinalizers is the very first part of the cleanup. I don't know if we guarantee this though.

Duncan Murdoch

> Is there any further documentation on what happens when an R session
> shuts down and in which order?

>

> /Henrik
>

> >
> >>
> >> Duncan Murdoch
> >>
> >>> Michael
> >>>
> >>> On Fri, Mar 11, 2011 at 10:19 AM, Jeffrey
> >>> Ryan<jeffrey.ryan@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
> >
> > ______________________________________________
> > 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 Received on Fri 11 Mar 2011 - 21:10:08 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 Sat 12 Mar 2011 - 13: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