Here is a simplified version of your problem > { sqrt }(c(2,4,8)) [1] 1.414214 2.000000 2.828427 Do you want that to act differently?
Bill Dunlap TIBCO Software wdunlap tibco.com On Fri, Oct 21, 2016 at 6:10 AM, Wilm Schumacher <wilm.schumac...@gmail.com> wrote: > Hi, > > I hope this is the correct list for my question. I found a wired behaviour > of my R installation on the evaluation of anonymous functions. > > minimal working example > > ### > f<-function(x) { > print( 2*x ) > }(2) > > class(f) > > f(3) > > f<-function(x) { > print( 2*x ) > }(4)(5) > > f(6) > ### > > leads to > > ### > > f<-function(x) { > + print( 2*x ) > + }(2) > > > > class(f) > [1] "function" > > > > f(3) > [1] 6 > Error in f(3) : attempt to apply non-function > > > > f<-function(x) { > + print( 2*x ) > + }(4)(5) > > > > f(6) > [1] 12 > Error in f(6) : attempt to apply non-function > > ### > > is this a bug or desired behavior? Using parenthesis of coures solves the > problem. However, I think the operator precedence could be the problem > here. I looked at the "./src/main/gram.y" and I think that the line 385 > | FUNCTION '(' formlist ')' cr expr_or_assign %prec LOW > should be of way higher precedence. But I cannot forsee the side effects > of that (which could be horrible in that case). > > If this is the desired behaviour and not a bug, I'm very interested in the > rational behind that. > > Best wishes, > > Wilm > > ps: > > $ R --version > R version 3.3.1 (2016-06-21) -- "Bug in Your Hair" > > ______________________________________________ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel > [[alternative HTML version deleted]] ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel