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

前端 未结 7 1309
不知归路
不知归路 2020-12-12 13:55

I program regularly in R in a professional context, and I write packages for clients or co-workers as well. Some of the programmers here have a Java background and insist on

7条回答
  •  抹茶落季
    2020-12-12 14:13

    Once upon a time, Roxygen2 didn't like S4 methods. As of 2017 (at least), they work together.

    I've had the misfortune of creating some functions that needed methods to work with both S3 and S4 classes. It has been incredibly painful to keep this code working over the years as R-core has multiple times changed details on how these systems interact and how Namespaces work and how Rcmd check works.

    If you don't like Google's style guide, then consider the comments of these well-known R package developers from this thread on R-help

    Frank Harrell "If you love computer science more than you value your own time, use S4."

    Terry Therneau wrote: For 90 percent of what I do I strongly prefer the loose (S3) rather than the rigid (S4) classes....My summary of S4 vs S3

    S4 has a large increment in: 1. nuisance to write 2. difficulty to debug 3. ability to write very obscure code 4. design

    S4 Gains: 5. ability to direct automatic conversions 6. validate the contents of a class object

提交回复
热议问题