Re: R-beta: scoping etc

Bill Venables (wvenable@attunga.stats.adelaide.edu.au)
Sun, 22 Feb 1998 10:11:26 +1030


Date: Sun, 22 Feb 1998 10:11:26 +1030
Message-Id: <9802212341.AA08923@attunga.stats.adelaide.edu.au>
From: Bill Venables <wvenable@attunga.stats.adelaide.edu.au>
To: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
Subject: Re: R-beta: scoping etc
In-Reply-To: <x2lnv5dvty.fsf@blueberry.kubism.ku.dk>
 <9802210629.AA08537@attunga.stats.adelaide.edu.au>

Peter Dalgaard writes:
 > Bill Venables <wvenable@attunga.stats.adelaide.edu.au> writes:
 > 
 > [Lots of sensible stuff]
 > > There are some cases when you do want to create something that is
 > > globally visible, but for the duration of the current expression
 > > only.  This is what the S structure known as "frame 1" is for.  I
 > > have yet to discover how to access this in R (or if it is
 > > possible at all) but it can be a useful device, even if the
 > > practice of using it to story temporary global variables is not
 > > free of the criticism that it, too, can be a dangerous
 > > side-effect.  Most powerful things are at the same time
 > > dangerous.
 > 
 > Now that you mention it... Actually, "frame 1" has always been one of
 > my favourite gripes with S. It may be useful as a scratch pad, and
 > with the S scoping probably necessary, but it breaks self-similarity:
 > Things viewed from inside a function can never be like they are from
 > the base level. This is not harmless, for instance it makes the
 > creation of interactive shell-type systems absolutely impossible,
 > because frame 1 will not be cleaned up before exit from the entire
 > system. 

Ah.  I was a bit too strong in saying that frame 1 is for making
things temporarily available globally.  It can be so used, but I
agree this is possibly not good style as, for another thing, it
destroys the possibility of safe recursion.

Normally frame 1 is used for .Last.expr and .Auto.print only.
That's fair enough, in my view.  It is handy being able to
determine whether or not the present expression stems from an
assignment or not, for example, and being able to turn on an off
the auto-print flag.

It's existence is not widely publicized in the official
documentation probably because the progenitors were aware that it
could easily be abused, but at the same time did not want to
prohibit its use altogether.  There are some situation where
there really is no other method other than using frame 1, frame 0
or (God forbid) the .Data directory.  An example is trying to
predict from an fitted model object formed within a function
using a data frame also formed within a function.

-- 
Bill Venables, Head, Dept of Statistics,    Tel.: +61 8 8303 5418
University of Adelaide,                     Fax.: +61 8 8303 3696
South AUSTRALIA.     5005.   Email: Bill.Venables@adelaide.edu.au

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