[S] Re: [S} Scope rules

John Maindonald (john.maindonald@anu.edu.au)
Tue, 30 Jun 1998 18:12:17 +1000 (EST)

Charles Roosen wrote
> The basic situation where this arises is that the user has created a
> model object, and then later applies a method to the object which
> needs to get the original data used to fit the model.

Unless one has a fairly broad definition of "the original data", the
problem is wider than that. Thus (1) if one uses
e. g. "formula=form0" to specify the name of a formula, rather than
giving the formula explicitly, it is in general necessary to assign
form0 in frame 1.

The same is true for:
(2) any variable used to identify a subset of the data. (I suppose
one could make this part of the data frame.)

(3) in trellis plots, any symbolic reference, e.g. to a vector of
text strings, which is included in the key= parameter.

(4) in gam models, smoothing parameters such as span in lo(span=my.span)

This is by no means a complete list.

Here, (1), (3) and (4) could be fixed rather easily, by ensuring that the
relevant expression is evaluated sooner rather than later. The overhead
for carrying a copy of the subsetting variable might also be acceptable.

> I think the concern about the scoping rules is something of a red
> herring caused by the modeling functions doing a form of
> pass-by-reference.

In the context of a discusson of ongoing development of S-PLUS, this
is fair comment. There are important broader computer science issues
here though, identified in Luke Tierney's elegant and definitive
dissection of the herring.

Charles then gives three possible approaches and adds:

> So maybe I should add:

> d) In the fitting function, stash the number of the frame containing
> the data in the model object. In the method functions, evaluate the
> name of the data in this frame.

> As a user, I'd find the {a, b, c} combination preferable, as passing
> frame numbers about is pretty techie. I'm interested in other
> opinions.

In many contexts, e.g. where the reference is back to the still
existing frame of the function from which the modelling function was
called, surely the "techie" bit would be invisible to the user. Is
the issue that this would get techie in situations where the frame had
ceased to exist?

John Maindonald email : john.maindonald@anu.edu.au
Statistical Consulting Unit, phone : (6249)3998
c/o CMA, SMS, fax : (6249)5549
John Dedman Mathematical Sciences Building
Australian National University
Canberra ACT 0200
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news