s-news
[Top] [All Lists]

Re: frames (?) question

To: s-news@lists.biostat.wustl.edu
Subject: Re: frames (?) question
From: Leonid Gibiansky <lgibiansky@emmes.com>
Date: Mon, 18 Nov 2002 16:50:00 -0500
In-reply-to: <200211181956.OAA23957@nightingale.hcp.med.harvard.edu>
I would like to thank Brian Ripley, Bill Dunlap, Alan Zaslavsky, Patrick Burns who answered my question. Below is the summary of the replies (I apologize, I cut-and-pasted portions of the replies to save space). Original question is attached.
Leonid

Brian Ripley wrote:

"It's a bug, but not in S. Something you have used has done
assign("runno", 101, w=0) or the equivalent. Now, people should not mess
with the session database (w=0) without documenting it, but equally it is
inadvisable to run S code you don't understand. Try find("runno")."

Bill Dunlap wrote:

" It sounds like two functions (or scripts) are expecting to use the global variable "runno",
but they choose to put it in 2 different, but both globally visible, places.

Do your functions expect to be sharing this variable? If so they have to
agree on where it is to be stored, in either the session database (where=0)
or the working database (where=1). The session database disappears at the
end of the current session so there is no chance of leaving an old value
of runno around if you use that. Use where=1 if you want the value to persist
from session to session. runno<-1 is the same as assign("runno",1,where=1).

If they don't want to share the variable they ought to use different names
for it. You might ask the writer of xpose3 for a list of global variables
it uses (they ought to be documented and they ought to have more
unusual looking names than runno, something like "xpose3.runno"
or longer would be better).

Since xpose3 appears to be using where=0, look at the objects there
(with objects(where=0)) to get a hint of what globals it is creating.
Splus puts .Options, .Copyright, and version there (and in Splus 2000,
.Program).
"

Alan Zaslavsky wrote:

" No, this is not a bug, this is performance in accord with documented
specifications. Objects in Frame 0 are persistent for the duration of
a session until removed, and are searched ahead of objects in the databases.
S+ cannot warn you about programming practices that might cause you to
get confused."

Patrick Burns wrote:

"I suspect that "xpose3" is writing its "runno" to database 0 (the session database). You
can see how S searches for objects on page 210 of S Poetry."

Original question:

I have a command-line interactive program (xpose3 for those who is familiar with the program) that uses a variable runno. I also happen to use the same name in my script that I am using from the script window. Then attempts to change runno from the script window do not give any warning and do not change runno (but lead to hidden errors in my script that uses the data associated with the incorrect runno):

> runno <- 102
> runno
[1] "101"


When I exited xpose3, I got a message on exit:

Warning messages:
"runno" assigned on database 1 but hidden by an object of the same name on database 0

Now when I am trying to change runno I am getting:

> runno <- 102
> runno
[1] "101"
Warning messages:
"runno" assigned on database 1 but hidden by an object of the same name on database 0

When I open runno via Object Explorer, I see "102" there.





<Prev in Thread] Current Thread [Next in Thread>