[R] infinite recursion using anonymous function

Steven C. Bagley steven.bagley at gmail.com
Sun Aug 15 00:23:13 CEST 2010


In R 2.11.1 on Mac OS 10.6.4, the following code works, but if the print statement is removed or commented out, then an infinite recursion results. Can someone explain what is going on? Thanks. --Steve


foo2=function(f1, f2){
  print(f1)
  function(x){
    f1(x) + f2(x) } }

foo=function(...) Reduce(foo2, list(...))

foo(sin, cos, tan)(1)



More information about the R-help mailing list