[R] Assign references

Seeliger.Curt@epamail.epa.gov Seeliger.Curt at epamail.epa.gov
Fri Oct 7 21:17:57 CEST 2005


Folks,

I've run into trouble while writing functions that I hope will create
and modify a dataframe or two.  To that end I've written a toy function
that simply sets a couple of variables (well, tries but fails).
Searching the archives, Thomas Lumley recently explained the <<-
operator, showing that it was necessary for x and y to exist prior to
the function call, but I haven't the faintest why this isn't working:

> myFunk<-function(a,b,foo,bar) {foo<<-a+b; bar<<-a*b;}
> x<-0; y<-0;
> myFunk(4,5,x,y)
> x<-0; y<-0;
> myFunk(4,5,x,y)
> x
[1] 0
> y
[1] 0

What (no doubt simple) reason is there for x and y not changing?

Thank you,
cur
--
Curt Seeliger, Data Ranger
CSC, EPA/WED contractor
541/754-4638
seeliger.curt at epa.gov




More information about the R-help mailing list