Skip to content
Prev 324844 / 398506 Next

generate simple function with pre-defined constants

On Thu, Jun 6, 2013 at 4:48 PM, Liviu Andronic <landronimirc at gmail.com> wrote:
I found one solution:
a <- 2
b <- 3
f <- eval(parse(text=paste("function(z)", a, "+ z * ", b)))
f
##function(z) 2 + z *  3

but I still have nightmares from:
If the answer is parse() you should usually rethink the question.
   -- Thomas Lumley
      R-help (February 2005)

Is there a nicer way to approach this? Thanks,
Liviu