[R] Assign references

Seeliger.Curt@epamail.epa.gov
Fri, 07 Oct 2005 19:17:57 -0000

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