Re: [R] Reducing a list of functions by composition fails

2010-08-05 Thread Mog
Thanks very much! Works fine now. I'll read up on R's evaluation model. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented,

Re: [R] Reducing a list of functions by composition fails

2010-08-05 Thread David Reiner
On Behalf Of Mog Sent: Thursday, August 05, 2010 3:55 PM To: r-help@r-project.org Subject: Re: [R] Reducing a list of functions by composition fails I realize that the Funcall example with an init parameter will work, but I'd like to be able to get a one-argument function/closure out of tha

Re: [R] Reducing a list of functions by composition fails

2010-08-05 Thread Gabor Grothendieck
On Thu, Aug 5, 2010 at 4:31 PM, Mog wrote: > Hi All, > > I'd like to be able to specify the ordered composition of several > functions. So I defined compose: > > compose <- function(f,g){ >  function(x){f(g(x))} > } > > and some simple test functions: > > plus2 <- function(x){x+2} > plus3 <- funct

Re: [R] Reducing a list of functions by composition fails

2010-08-05 Thread Mog
I realize that the Funcall example with an init parameter will work, but I'd like to be able to get a one-argument function/closure out of that reduction, if at all possible. Sorry, I under-specified in my question. Thanks! __ R-help@r-project.org maili

[R] Reducing a list of functions by composition fails

2010-08-05 Thread Mog
Hi All, I'd like to be able to specify the ordered composition of several functions. So I defined compose: compose <- function(f,g){ function(x){f(g(x))} } and some simple test functions: plus2 <- function(x){x+2} plus3 <- function(x){x+3} plus4 <- function(x){x+4} > (compose(plus2,compose(