This can be solved using the eval-parse construct, although I highly recommend that you use the wrong construct. This often causes more problems than anything else. But I could not get a decent way to do this.
vector_of_functions = NULL for (i in 1:4) { vector_of_functions = c(vector_of_functions, eval(parse(text=paste("function(number) func(number=number, coefficient=",i,")")))) }
The reason is as Aaron explained: everything in the definition of a function is accepted in the same way as before the evaluation of a function.
A quick note: this is especially a list of functions, not a vector. It is not possible to have a function type vector. This is also completely useless, since you need to select a function using the [[]] index before you can use it. Then I just add an argument instead of defining a function for each possible value of one of the arguments.
What you want to achieve is unclear, but if you want to apply func with different coefficients, I wonder why you just don't:
> x <- c(10,20,30) > sapply(1:4,function(y)func(number=x,coefficient=y)) [,1] [,2] [,3] [,4] [1,] 10 20 30 40 [2,] 20 40 60 80 [3,] 30 60 90 120
Option on the topic of Marek (avoiding parsing):
vector_of_functions = NULL for (i in 1:4) { vector_of_functions = c(vector_of_functions, eval(substitute(function(number) func(number=number, coefficient=i),list(i=i)))) }
1L etc. you will get, just indicate that they are exact integers (which take up less memory space).