[R] using object reference

Rajarshi Guha rxg218 at psu.edu
Wed Mar 3 14:48:59 CET 2004


On Wed, 2004-03-03 at 04:55, Spencer Graves wrote:
>       Yes, but use sparingly, because any use of "<<-", "assign", etc., 
> from within a function to change something other than what appears in 
> the standard return from a function call generates "spaghetti code" that 
> is difficult to maintain.  A month or a year from now, someone (the 
> developer or someone else) may have difficulty understanding how "z" got 
> created or changed. 

Thanks to everybody for their responses.

I do realize that changing a variable in the global namespace from a
function is not a good way to design code however for what I want I
can't see a way around it.

As I mentioned in an earlier mail the function creates a Tk window with
a text entry. When the user clicks on the button in the window the
buttons callback function gets the text of the entry box and places it
in the attribute 'a' of the variable passed to the function.

When I call my function it draws the Tk window and then returns to the R
prompt.

So doing something like

x <- add.text(x)

Does'nt give me what I want (it makes x a tclObj) and I can see why it
would not work this way.

Is there is a way that I can achieve this without having to use <<- ?

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <rxg218 at psu.edu> <http://jijo.cjb.net>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
COBOL is for morons.
-- E.W. Dijkstra




More information about the R-help mailing list