If you redifine the class of a
, for example like class(a)<-"ownfunction"
(or better yet class(a)<-c("ownfunction","function")
, and make your "+.function"
as "+.ownfunction"
, then (a+a)(2)
works.
It seems that the function
class is treated in some special way: If you run debug("+.function");(a+a)(2)
you see that "+.function"
is not even called.
EDIT: see comments.