Skip to content

sys.on.exit not working (PR#7665)

3 messages · Mark Bravington, Brian Ripley, Peter Dalgaard

#
Full_Name: Mark Bravington
Version: 2.0.1
OS: Windows XP
Submission from: (NULL) (140.79.22.104)


'sys.on.exit()' doesn't seem to be working, since R1.7.1 at least:

soe.test <- function() { 
  on.exit( cat( 'In exit code\n'))
  str( sys.on.exit()) # should display "language..." I think
  12 
}

(A similar bug was apparently fixed for version 0.65!)
#
It is working as documented: there is no on.exit set for str, is there?

      'sys.on.exit()' retrieves the expression stored for use by
      'on.exit' in the function currently being evaluated. (Note that
                                ^^^^^^^^^^^^^^^^^^^^^^^^^
      this differs from S, which returns a list of expressions for the
      current frame and its parents.)

I see you have looked at PR#269, but did not notice the crucial 
difference: here the current function is str (it is evaluating its 
arguments), not soe.test.
On Mon, 7 Feb 2005 mark.bravington@csiro.au wrote:

            
Please read the FAQ: we don't want R-bugs clogged up with `doesn't seem to 
be working' reports, and we do say so.
One difference being that PR#269 was a bug, and this is not.
#
Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:
It does, however, point to a subtlety with the sys.xxx functions,
which is liable to confuse users to the point of submitting spurious
bug reports. Perhaps we should add a note to the help page (in the
vain hope that people will read it).

Notice, BTW, that this exposes a slightly anomalous handling of the
"<-" operator. AFAIK this is common to all .Primitive calls, as
opposed to .Internal and other function calls: They do not create a
new context, hence do not increase sys.nframe() and sys.whatever in
the arguments still refer to the callers frame.
function() {
  on.exit( cat( 'In exit code\n'))
  a <- sys.on.exit() ; str(a)
  12
 }
language cat("In exit code\n")
In exit code
[1] 12

but if you replace "<-" with a corresponding call to assign(), then
you get.
NULL
In exit code
[1] 12