[R] Assign references

From: <Seeliger.Curt_at_epamail.epa.gov>
Date: Sat 08 Oct 2005 - 05:17:57 EST


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@epa.gov

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Received on Sat Oct 08 05:29:54 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:40:39 EST