Re: [S] scope rules

ballr@rimu.fri.cri.nz
Fri, 26 Jun 1998 15:10:27 +1200


I think John Maindonald has hit on an important aspect of the problem. I
have always found it frustrating trying to automate top-level calculations
using modelling functions within a function. Usually it is easier to cut
and paste and query-replace different versions of the calculation.

What occurs when you pass a fitted model object into another function is
that other object-oriented functions like predict no longer work on the
object because reference needs to be made back to other associated objects
in the calling frame which a referred to by the fitted model object (e.g.
the data frame or model matrix). The associated objects, and how to
evaluate them are effectively a part of the object in any reasonable object
oriented semantics. I see this problem as an incompatibility between the
object oriented and functional aspects of Splus. Maybe this has come about
because the object-oriented stuff came later.

One solution, is for a modified argument passing convention for
objects--each object with associated objects contains a frame number ('home
frame') for evaluating the associated objects (e.g. sys.parent(1)). This
would be automatically updated by Splus (e.g. to sys.parent(2) ) when the
object is passed to a function.

Then e.g. :

x <- 1:10
a <- data.frame(x=x,y=x^^2 + rnorm(10)
fit1 <- lm(x ~ y, data=a) # home frame for fit1= top level
f1 <- function(fit,...){
...
f2(fit) # home frame for fit =sys.parent(1)
...
}
f2 <- function(fit,...){
b <- data.frame(x=12)
predict(fit,newdata=b) # home frame = sys.parent(2) within predict
}

f1(fit1,....)

should work.

Rod Ball

-----------------------------------------------------------------------
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