Hi, Could someone point me in the right direction for documentation on the following question? Let's say I have two objects a and b of classes A and B, respectively. Now let's say I write a function foo that does something similar to objects of type A and B. Basically I want to overload the function in C++ talk, so if I give foo and object of type A something (and this is my question) dispatches the call to, say, foo.A, and if I give foo and object of type B something dispatches the call to, say, foo.B. I want to write foo.A and foo.B. How to I perform the method dispatch? From what I understand there are two ways in R: S3 and S4. What is the simple S3 way? Thanks! Jack. --------------------------------- [[alternative HTML version deleted]]
Carlos J. Gil Bellosta
2007-Jun-30 23:16 UTC
[R] [R-SIG-Finance] Method dispatch in functions?
Look at the UseMethod function. The help for the "print" method, a heavily overloaded function, can also help. Regards, Carlos J. Gil Bellosta http://www.datanalytics.com On Thu, 2007-06-28 at 09:05 -0700, John McHenry wrote:> Hi, > > Could someone point me in the right direction for documentation on the following question? > > Let's say I have two objects a and b of classes A and B, respectively. > Now let's say I write a function foo that does something similar to > objects of type A and B. Basically I want to overload the function > in C++ talk, so if I give foo and object of type A something (and this > is my question) dispatches the call to, say, foo.A, and if I give foo > and object of type B something dispatches the call to, say, foo.B. > > I want to write foo.A and foo.B. How to I perform the method > dispatch? From what I understand there are two ways in R: > S3 and S4. What is the simple S3 way? > > Thanks! > > Jack. > > > --------------------------------- > > [[alternative HTML version deleted]] > > _______________________________________________ > R-SIG-Finance at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-sig-finance > -- Subscriber-posting only. > -- If you want to post, subscribe first.
Apparently Analagous Threads
- Dispatch method on S3 or S4 class
- S3 generic method dispatch on promises
- rbind has confusing result for custom sub-class (possible bug?)
- Why S4 methods of S3 'base' generics are not used in 'base' functions ?
- "Overloading" some non-dispatched S3 methods for new classes