Skip to content
Prev 40292 / 63424 Next

S3 method dispatch - can methods come from the enclosing environment?

I was surprised to see that S3 methods are not found if they only reside in the enclosing environment.  E.g.:
+   print.tst <- function(x, ...) cat("found it!")
+ 
+   function(x) print(x)
+ })
[1] "The cat sat on the mat."
So the answer to the question posed in the subject line is apparently "no". Perhaps this is well known and fully documented somewhere, but if so it has eluded me.  Is there some reason for this?  

I'm not sure if this is a bug, a feature, or a proposal for development, but I would welcome people's views on this curious little issue.

Bill Venables.