Prof Brian Ripley <ripley@stats.ox.ac.uk> writes:
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:
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:
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.
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!)
One difference being that PR#269 was a bug, and this is not.
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.
soe.test
function() {
on.exit( cat( 'In exit code\n'))
a <- sys.on.exit() ; str(a)
12
}
soe.test()
language cat("In exit code\n")
In exit code
[1] 12
but if you replace "<-" with a corresponding call to assign(), then
you get.
soe.test()
NULL In exit code [1] 12
O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907