G'day Brian, >>>>> "BDR" == Prof Brian Ripley <[EMAIL PROTECTED]> writes:
>> I found in the R language definition manual the passage that >> discourages users of assigning objects within function calls >> since it is not guaranteed that the assignment is ever made >> because of R's lazy evaluation model. But this does not seem >> to explain the above behaviour since the argument to print is >> evaluated. If I replace sys.on.exit() with, say, ls() in both >> functions, then they produce the same output (and the output >> that I expect). Why does f2() not work with sys.on.exit()? BDR> It does work, but you seems to have misunderstood what it BDR> does. See e.g. the `bug' report discussed at BDR> http://tolstoy.newcastle.edu.au/~rking/R/devel/05/02/2112.html Mmh, mea culpa, I am a bit red-faced here, in my quest to find out what was going on, I checked about everything (including a private e-mail to an R-core member) but the bug repository and the help page of sys.on.exit(). I guess that if I have read the latter, I would have figured out what was going on. Instead I was satisfied with what the on.exit() help page stated in its "see also" section: \seealso{ \code{\link{sys.on.exit}} to see the current expression. } May I request that this help page is changed according to the patch attached below to clarify on the on.exit() help page what it is that sys.on.exit() is returning? BDR> You might find BDR> g <- function(test) {} BDR> f2 <- function(){ BDR> par.def <- par(no.readonly=TRUE) BDR> on.exit(par(par.def)) BDR> g(tt <- sys.on.exit()) BDR> str(tt) BDR> invisible() BDR> } BDR> f2() BDR> illuminating. Mmh, in this code the function g is not evaluating its argument. So I would expect an error message in f2() that tt is not defined no matter which function (sys.on.exit, ls, ...) I am using in the call to g() within f(). Exactly the situation about which the R language definition is warning, so this seems to be a different trap than the one I stepped into.... Cheers, Berwin
Index: src/library/base/man/on.exit.Rd =================================================================== --- src/library/base/man/on.exit.Rd (revision 36611) +++ src/library/base/man/on.exit.Rd (working copy) @@ -19,7 +19,8 @@ \arguments{ \item{expr}{an expression to be executed.} \item{add}{if TRUE, add \code{expr} to be executed after any previously - set expressions.} + set expressions; otherwise (the default) \code{expr} will overwrite + any previously set expressions.} } \references{ Becker, R. A., Chambers, J. M. and Wilks, A. R. (1988) @@ -27,7 +28,9 @@ Wadsworth \& Brooks/Cole. } \seealso{ - \code{\link{sys.on.exit}} to see the current expression. + \code{\link{sys.on.exit}} which returns the expression stored for use + by \code{on.exit()} in the function in which \code{sys.on.exit()} is + evaluated. } \examples{ opar <- par(mai = c(1,1,1,1))
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel