Skip to Content
R in a Nutshell
book

R in a Nutshell

by Joseph Adler
January 2010
Beginner
634 pages
19h 50m
English
O'Reilly Media, Inc.
Content preview from R in a Nutshell

Chapter 10. Object-Oriented Programming

The R system includes some support for object-oriented programming (OOP). OOP has become the preferred paradigm for organizing computer software; it’s used in almost every modern programming language (Java, C#, Ruby, and Objective C, among others) and in quite a few old ones (Smalltalk, C++). It’s easy to understand why: OOP methods lead to code that is faster to write, easier to maintain, and less likely to contain errors. Many R packages are written using OOP mechanisms.

If all you plan to do with R is to load some data, build some statistical models, and plot some charts, you can probably skim this chapter. On the other hand, if you want to write your own code for loading data, building statistical models, and plotting charts, you probably should read this chapter more carefully.

R includes two different mechanisms for object-oriented programming. As you may recall, the R language is derived from the S language. S’s object-oriented programming system evolved over time. Around 1990, S version 3 (thus S3) introduced class attributes that allowed single-argument methods. Many R functions (such as the statistical modeling software) were implemented using S3 methods, so S3 methods are still around today. In S version 4 (hence S4), formal classes and methods were introduced that allowed multiple arguments, more abstract types, and more sophisticated inheritance. Many new packages were implemented using S4 methods (and you can find S4 implementations ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

R in a Nutshell, 2nd Edition

R in a Nutshell, 2nd Edition

Joseph Adler
The Big R-Book

The Big R-Book

Philippe J. S. De Brouwer
R Packages

R Packages

Hadley Wickham

Publisher Resources

ISBN: 9781449377502Supplemental ContentErrata Page