Wednesday 12 December 2012

goose leather When does it pay off to use S4 methods in R programming

When will it repay to use S4 methods in R programming

I program regularly in R inside a professional context, and that i write packages for clients or co-workers too. A few of the programmers here have a Java background insist upon doing everything the object-oriented way, using S4 methods. My experience on the other hand is that S4 implementations often perform worse and result in a much more headache when attemping to get the code do what goose leather need it to do.

I definitely agree that in some cases, goose leather need to be able to construct complex objects or append existing objects inside a controlled manner. But most of the time, S4 implementations may be easily done using classic lists as well, without all of the hassle like defining standardGeneric, methods, constructors, initializers and the likes.

EDIT : For clarity, I actually do appreciate the answers and the discussion about OO in general in R. You can easily program the item oriented way by utilizing lists only and setting all attributes manually. My Colleagues , from a Java background, call something OOP whether it forces goose leather to do it the item oriented way. S3 doesn S4 does for them, and I feel it exactly the same. Your mile can vary, but I think goose leather do agree that S3 and S4 are two different beasts. I wanted some ideas about the use of S4, not some semantic discussion by what exactly is OOP in R. Joris Meys Aug 30 10 at 22:26

Im assuming this doesnt directly apply to goose leather, but if goose leathere developing packages for Bioconductor theres an incentive to make use of S4 because they actively encourage its use and have for that better a part of ten years now - so that all of the core packages make heavy use of S4.

Ive found all the extra overhead to become a pain - the setGeneric, setMethod, dealing with NAMESPACE, etc. That being said, Ive found the structure it imposes, possibility of extensibility along with other such things can be worth it. As with everything, goose leather will find tradeoffs involved. Everything being said, I am inclined to stay away from S4 heavily in my own code unless Im being told to do this.

I learnt S4 in order to extend the Spatial sp classes for animal track data. It had been the best choice most consistent, general and closely matching to many GIS definitions in the available options to prevent writing everything required from scratch. I do not find S4 as onerous as many people say, but Im now used to exploring the underlying structure of objects such as this. The performance is good too, It can be achieved well, though when done poorly goose leather will find performance traps.

If spatial information is of interest for goose leather, spatstat is a great one of how goose leather can perform a large amount of similar items to sp in S3, though just like seemingly everything spatial . . . theres hardly ever clean analogies between data structures in various softwares.

I hear goose leather. I don even think it bad or anything - I don agree w/ everything however, goose leather know what they are saying about opinions. And yes, having something is better than nothing, but I never really been comfortable with Google being the arbiters here great deal of thought directly conflicts w/ the private types of various prominent R-core members. Its been incredibly painful to keep this code working through the years as R-core has multiple times changed information on how these systems interact and just how Namespaces work and how Rcmd check works.

No comments:

Post a Comment