Re: [S] constructing function names from strings

Prof Brian Ripley (
Mon, 27 Apr 1998 13:47:38 +0100

From: Steve Roberts <>
> Dumb question of the day?....
Not at all. These things are tricky to get right.

> 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)...))

That should be ms( ~ func(things)). As far as I know as.formula works,

fit <- ms(as.formula(paste("~", "something",method, "(things)",sep="")))


my.function<-function( method, other.things)
#build function name
ms(as.formula(paste("~", "root.",method,"(things)",sep="")),
#define the real functions
root.a<-function(things) {things^2}
root.b<-function(things) {(things-1)^2}

> my.function("b", 0)
value: 2.910541e-20
formula: ~ root.b(things)
1 observations
call: ms(formula = as.formula(paste("~", "root.", method, "(things)", sep = "")), start = c(things = 4))

In similar contexts use get on the function name, or

Brian Ripley
This message was distributed by To unsubscribe
send e-mail to with the BODY of the
message: unsubscribe s-news