[R] substituting values into a function

Thomas Yee yee at scitec.auckland.ac.nz
Sun Oct 10 22:26:09 CEST 1999

Hi everybody,

In Splus, the following works fine.

foo1 <- function(x, const)
    x + const

foo2 <- function(x, const)
    x * const

const1 <- 1
const2 <- 2
foo <- substitute(function(x) {
    a <- foo1(x, const1)
    b <- foo2(a, const2)
}, list(const1=const1, const2=const2))


In R, the code doesn't work, as foo is of mode "call", and
as.function(foo) gives an error. I could add the arguments const1 and
const2 to foo, but that would be less elegant for me.  Also, it would
be needful to have the same code running in both S and R.  Assistance
with the problem would be greatly appreciated. Thanks in advance.


r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list