s-news
[Top] [All Lists]

[S] constructing function names from strings

To: "'s-news@wubios.wustl.edu'" <s-news@wubios.wustl.edu>
Subject: [S] constructing function names from strings
From: Steve Roberts <sroberts@PICR.man.ac.uk>
Date: Mon, 27 Apr 1998 12:34:38 +0100
Sender: owner-s-news@wubios.wustl.edu
Greetings,

Dumb question of the day?....  

I have a fitting routine with an string argument "method" which calls MS
with a function whose name I can construct using the string argument
"method" using paste (func<-paste("something",method,sep=".") I then
want to use func as a  function in the formula argument in the ms call
(fit<-ms(func(things)...))
I think I need the correct incantation of substitute, deparse,
expression and eval, but despite a lot of playing can't get it to work.
I can do it if I put the function name as the argument in the function
call, with no need for any messing about. 

Any suggestions? I bet it's simple but the documentation is rather
obscure! (My copy of V&R is on order!)

Steve.

===============================================
some pseudo S code:

-------------------
#what I want is this

my.function<-function( method, other.things)
{
#build function name
func<-paste("root",method,sep=".")

#call MS with function
msfit<-ms(~func(various.things),more.things)
}

#define the real functions
root.a<-function(things) {...}
root.b<-function(things) {...}

#call my function to use the various fitting routines...
my.function(a,other.things)
my.function(b,other.things)

-----------------
#this works, but is not as flexible for my application

my.function<-function(func, other.things) 
{
msfit<-ms(~func(various.things),more.things)
}
define the real functions
root.a<-function(things) {...}
root.b<-function(things) {...}

#call my function to use the various fitting routines...
my.function(root.a,other.things)
my.function(root.b,other.things)

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

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