[S] scoping again and the use of get and assign

Max_Kuhn@ms.bd.com
Wed, 7 Oct 1998 13:31:37 -0400


From: Max Kuhn@BDX on 10/07/98 01:31 PM

Hello,

I'm creating a function "func2" that is called from nlminb within a
function "func1":

func2<-function(beta, ..x){
- some computations -
objective.function
}

and

func1<-function(arguments){
- some computations -
create .x
fit <- nlminb(start, objective = func2, lower = bounds, ..x = .x)
fit
}

(This type of structure is similar to the logitreg function on page 293 of
V&R, 1997. Their
example defines the objective function within the same function that calls
ms, not
nlminb - I have boundaries on the parameters)

>From the command line, I would call func1. However, the type of message I
get is:

Error in f(c(-34.1748756062704, 5.80524825837575, 0.5)): Object ".x" not
found
Dumped

Question # 1: Why isn't the object .x found? (I'm sure that there is a
simple, obvious answer to why this doesn't work)

My work-around was to use:

.x <- get(".x", frame = sys.parent(3))
within func2. It works, but I'm sure it is slowing down the computations in
nlminb.

Question #2: Why does

assign("..x", .x, frame = sys.parent(3))

fail when substituted for the get function (the error message is the same
as above)?

I realize that these question are a result of my naive understanding of
S-plus scoping rules which have be
discussed recently on this list, so I apologize in advance. Thanks,

Max

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