Skip to content
Prev 15052 / 63424 Next

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

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