[R] on.exit processing

james.holtman@convergys.com james.holtman at convergys.com
Mon Sep 10 17:01:39 CEST 2001


I have encountered a 'strange' behavior in the 'on.exit' processing.  I had
a function where I setup an 'on.exit' condition and then later on added to
it with an 'on.exit({...}, add=T)'.  What appeared to happen is that on
subsequent calls to the function, even if only the first 'on.exit' was
called, it was still executing the one with the 'add=T'.

I am using Version 1.3.0  (2001-06-22) on Windows 2000.

Here is a small sample of what is happening.  The function conditionally
sets up the on.exit, and as you can see, each time the 'second' one is
setup, it just keeps adding to what is output:


> x.func <- function(x=0){
+     on.exit({cat('first exit call\n')})
+     if (x == 1) on.exit({cat('second exit call\n')}, add=T)
+     invisible(NULL)
+ }
> x.func(0)   # only the 'first' exit
first exit call
> x.func(1)   # both 'first' & 'second'
first exit call
second exit call
> x.func(0)   # only the 'first'
first exit call
second exit call         #<<  shouldn't be here
> x.func(1)   # both 'first' & 'second'
first exit call
second exit call
second exit call         #<<  shouldn't be here
> x.func(1)   # both 'first' & 'second'
first exit call
second exit call
second exit call         #<<  shouldn't be here
second exit call         #<<  shouldn't be here
> x.func(1)   # both 'first' & 'second'
first exit call
second exit call
second exit call         #<<  shouldn't be here
second exit call         #<<  shouldn't be here
second exit call         #<<  shouldn't be here
>

--

NOTICE:  The information contained in this electronic mail transmission is
intended by Convergys Corporation for the use of the named individual or
entity to which it is directed and may contain information that is
privileged or otherwise confidential.  If you have received this electronic
mail transmission in error, please delete it from your system without
copying or forwarding it, and notify the sender of the error by reply email
or by telephone (collect), so that the sender's address records can be
corrected.


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list