s-news
[Top] [All Lists]

The "assign" problem: Solution

To: <s-news@lists.biostat.wustl.edu>
Subject: The "assign" problem: Solution
From: "Steve Su" <s.su@qut.edu.au>
Date: Fri, 15 Nov 2002 15:43:06 +1000
Importance: High
Dear All,

After some suggestions and recommendations from people on the mailing
list I propose the following solution:

nm<<-names(as.list(match.call()))
lapply(2:length(nm), function(i)
assign(names(nm[i]),eval(parse(text=as.character(nm[i]))),immediate=T,fr
ame=1))

Thanks for your attention.


************************************************************************
*****************

Dear All,

Apologies for those of you who cannot read my e mail. I have convert my
e mail to plain text now.

I am wondering if there is a more elegant way of doing the following in
Splus:

Lets say I have the following function:

fun.aggregate.simu.1<-function(d.par.matrix,po.par.matrix,s.par.matrix,n
,time.scale.s=12,time.scale.b=365,begin=1,mode="m",modem=4){

assign("A",list(rep(NULL,n)),frame=1,immediate=T)
assign("k",1,frame=1,immediate=T)
assign("d.par.matrix",d.par.matrix,frame=1,immediate=T)
assign("po.par.matrix",po.par.matrix,frame=1,immediate=T)
assign("s.par.matrix",s.par.matrix,frame=1,immediate=T)
assign("time.scale.s",time.scale.s,frame=1,immediate=T)
assign("time.scale.b",time.scale.b,frame=1,immediate=T)
assign("begin",begin,frame=1,immediate=T)
assign("mode",mode,frame=1,immediate=T)
assign("modem",modem,frame=1,immediate=T)

etc...

Is there a way of assigning all the arguments of a function inside the
function immediately? Rather than having to type each one individually
as shown above? Also if I want to introduce new variables like A and k
later on in the program is there a way of defining their presence in a
more elegant way? 

Thanks in advance!



************************************************************************
**************

 Steve Su (s.su@qut.edu.au)   
 PhD student. 

 School of Accountancy
 School of Mathematical Sciences
 Queensland University of Technology 

 Postal Address: Steve Su, School of Accountancy, QUT, PO Box 2434,
Brisbane,
 Queensland, Australia, 4000.  


 Phone:  +61 7 3864 2017
 Fax:   ; +61 7 3864 1812     
 Mobile: 0421  840  586 
     .                              
   _--_|\                 
  /      QUT                                  
 
\_.--._/                                                                
          
        v                                              
                                                                     
************************************************************************
**************     



<Prev in Thread] Current Thread [Next in Thread>