R 和面向对象编程 [英] R and object oriented programming

查看:27
本文介绍了R 和面向对象编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 R 中以一种或另一种方式进行面向对象的编程是非常可能的.但是,与 Python 不同的是,有很多方法可以实现面向对象:

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:

我的问题是:

在 R 中,这些面向对象编程的方式有哪些主要区别?

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

理想情况下,这里的答案将作为 R 程序员的参考,以帮助他们决定哪种 OO 编程方法最适合他们的需求.

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.

推荐答案

S3 课程

  • 不是真正的对象,更多的是命名约定
  • 基于 .语法:例如对于打印,print 调用 print.lm print.anova 等.如果没有找到,print.default
  • 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

中四班

参考类

原型

  • ggplot2 最初是用 proto 编写的,但最终将使用 S3 重写.
  • 简洁的概念(原型,而不是类),但在实践中似乎很棘手
  • 下一版本的 ggplot2 似乎正在远离它
  • 概念和实现的描述

R6 类

  • 参考
  • 不依赖于 S4 课程
  • "创建 R6 类与引用类类似,只是不需要将字段和方法,并且您不能指定字段的类型."
  • 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."

这篇关于R 和面向对象编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆