Re: [Rd] Enlightenment sought and a possible buglet in vector.Rd

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Fri 02 Dec 2005 - 11:37:37 GMT

On Fri, 2 Dec 2005, Berwin A Turlach wrote:

> Secondly, I stumbled across two behaviours of R that I cannot explain
> but would like to know why R behaves as it does. But since I expect
> the explanations to be quite technical, I though that r-devel is the
> more appropriate list to ask on than r-help.
>
> The first example is the following:
>
> > f1
> function(){
> par.def <- par(no.readonly=TRUE)
> on.exit(par(par.def))
> tt <- sys.on.exit()
> print(tt)
> str(tt)
> invisible()
> }
> > f1()
> par(par.def)
> language par(par.def)
> > f2
> function(){
> par.def <- par(no.readonly=TRUE)
> on.exit(par(par.def))
> print(tt <- sys.on.exit())
> str(tt)
> invisible()
> }
> > f2()
> NULL
> NULL
>
> 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()?

It does work, but you seems to have misunderstood what it does. See e.g. the `bug' report discussed at

         http://tolstoy.newcastle.edu.au/~rking/R/devel/05/02/2112.html

You might find

g <- function(test) {}
f2 <- function(){

        par.def <- par(no.readonly=TRUE)
        on.exit(par(par.def))
        g(tt <- sys.on.exit())
        str(tt)
        invisible()

}
f2()

illuminating.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Fri Dec 02 22:47:29 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:34 GMT