Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

oop - R and object oriented programming

Object oriented programming in one way or another is very much possible in R. However, unlike for example Python, there are many ways to achieve object orientation:

My question is:

What major differences distinguish these ways of OO programming in R?

Ideally the answers here will serve as a reference for R programmers trying to decide which OO programming methods best suits their needs.

As such, I am asking for detail, presented in an objective manner, based on experience, and backed with facts and reference. Bonus points for clarifying how these methods map to standard OO practices.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

S3 classes

  • Not really objects, more of a naming convention
  • Based around the . syntax: E.g. for print, print calls print.lm print.anova, etc. And if not found,print.default

S4 classes

Reference classes

proto

  • ggplot2 was originally written in proto, but will eventually be rewritten using S3.
  • Neat concept (prototypes, not classes), but seems tricky in practice
  • Next version of ggplot2 seems to be moving away from it
  • Description of the concept and implementation

R6 classes

  • By-reference
  • Does not depend on S4 classes
  • "Creating an R6 class is similar to the reference class, except that there’s no need to separate the fields and methods, and you can’t specify the types of the fields."

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...