Re: Dataframes as arguments to functions?

Erin Hodgess (hodgess@uhdux2.dt.uh.edu)
Wed, 28 Jan 1998 14:43:17 -0600


From: "F.Tusell" <etptupaf@agesi.bs.ehu.es>
To: S-news@utstat.toronto.edu
Subject: Dataframes as arguments to functions?
Status: R

F. Tusell Writes:
I would like to code a program in such a way dat a dataframe is worked
upon by a number of different functions. Something like,

M <- as.dataframe(xxxx)
function1(M)

where function1() in turn calls function2(M) and so on, up to a three
or four level deeps nesting. Now, in the invocation of function1(M),
the dataframe M is found correctly, but further nested calls (to
function2(M), etc.) do not seem to propagate the argument.

I have read the S-Plus manual, and I understand that this is not a
bug, but a design decision --as it should be. My question is: how can
I do what I want (basically, pass dataframes as in a FORTRAN
call-by-reference subroutine)? Is there any other way to go around?

Any help appreciated.

ft.

---------------------------------------------------------------------
Fernando TUSELL etptupaf@bs.ehu.es
Departamento de Econometria y Estadistica
Facultad de CC.EE. y Empresariales Tel. (94) 4797433
Avenida Lendakari Aguirre, 83 +34,4,4797433
E-48015 BILBAO (Spain) Fax: 4797554
---------------------------------------------------------------------

What you might want to do is use the assign statement; i.e.,

M <- as.dataframe(xxx)
assign("M",M,1)
function(M)

This should take care of your problem.

Good Luck!

Sincerely,
Erin Hodgess
Assistant Professor
Dept. of Computer and Mathematical Sciences
University of Houston -- Downtown
e-mail: hodgess@uhdux2.dt.uh.edu