sys.on.exit appears non-functional (PR#269)

Peter Dalgaard BSA p.dalgaard@biostat.ku.dk
08 Sep 1999 01:03:45 +0200


ripley@stats.ox.ac.uk writes:

> As far as I can see sys.on.exit() does not work. The following
> will give a non-null result in S, and seems about the simplest possible
> usage.
> 
> test <- function() {
>   on.exit(print(1))
>   ex <- sys.on.exit()
>   str(ex)
>   cat("exiting...\n")
> }
> > test()
>  NULL
> exiting...
> [1] 1
> 
> Looking at the code suggests that on.exit is installing the code in
> a different context from the one sys.on.exit is looking in, but this is
> daunting for non-experts.

Not really that hard, once I realised that R_GlobalContext is not a
global constant and that R_ToplevelContext is the bottom of the
context stack... sys.on.exit is a function that calls a .Internal.
This inserts an extra context layer - calling the .Internal directly
works - and one just had to look one level further up.

Will commit for 0.65.1 in a moment.

-- 
   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
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel 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-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._