Re: [Rd] variable problem

From: Tom McCallum <>
Date: Tue 07 Nov 2006 - 20:50:21 GMT

Works like a charm - thank you very much.


On Tue, 07 Nov 2006 20:45:04 -0000, Vladimir Dergachev <> wrote:

> On Tuesday 07 November 2006 3:28 pm, Tom McCallum wrote:
>> Hi everyone,
> Hi Tom,
> Would this snippet work:
> for(i in 1:length(mylist)), mylist[i])
> On the other hand it is not easy to see why you would want to call
> the
> same function with differently named arguments - perhaps what you are
> really
> trying to do has a different (and better) solution ?
> best
> Vladimir Dergachev
>> I am not sure this is possible so I would be interested in your
>> responses. Say I have a variable 'v' with the string "myargument" in
>> and
>> I have a function 'f' that takes this argument as follows;
>> f <- function( myargument=5 ) {
>> ... does something...
>> }
>> Is there anyway I can say something like;
>> f( v=10 ) such that it will be evaluated as f( myargument=10 ).
>> I presume there may be some use eval and substitute but if someone could
>> point me in the right direction then that would be great.
>> The end idea is to have a list of m items, declared somewhere else,
>> which
>> can be evaluated as particular arguments named after their list names
>> e.g
>> mylist <- list( "a"=1, "b"=2, "c"=3 )
>> which can be passed to a function taking arguments a,b, or c and it will
>> be able to evaluate them accordingly :
>> long hand this would evaluate to something like
>> f( a=mylist[["a"]] );
>> f( b=mylist[["b"]] );
>> f( c=mylist[["c"]] );
>> but I would have actually rewritten something like
>> for ( myvar in names( mylist ) ) {
>> f( some_clever_substitution_to_act_as_argument(myvar) = mylist[[ myvar
>> ]] );
>> }
>> I hope I have explained myself clearly enough, if not please say so and
>> I
>> will try and give a better example.
>> Many thanks for your help
>> Tom

Dr. Thomas McCallum
Systems Architect,
Level E Limited
ETTC, The King's Buildings
Mayfield Road,
Edinburgh EH9 3JL, UK
Work  +44 (0) 131 472 4813
Fax:  +44 (0) 131 472 4719

Level E is a limited company incorporated in Scotland. The contents of  
this e-mail are privileged and/or confidential. If you are not the  
intended recipient, please
notify the sender and ensure this e-mail is deleted and not read, copied  
or disclosed. It is your responsibility to scan this e-mail and any  
attachments for
computer viruses or other defects. Level E does not accept liability for  
any loss or damage which may result from this e-mail or any attachment.  
E-mail is not secure
and can be intercepted, corrupted or amended. Level E does not accept  
liability for errors or omissions arising as a result of interrupted or  
defective transmission.
Any views, opinions, conclusions or other information in this e-mail which  
do not relate to the business of Level E Limited are not authorised by  
Level E. Unless
specifically stated and authorised by Level E, nothing in this e-mail  
shall be taken to be an offer or acceptance of any contract of any nature.  
E-mail entering or leaving Level E's system is subject to random  
monitoring and recording.

______________________________________________ mailing list
Received on Wed Nov 08 07:56:09 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 07 Nov 2006 - 21:30:37 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.