The Art of R Programming

(WallPaper) #1
Let’s try it out:

> joe
Joe has a salary of 55000 and is in the union

9.3 S3 Versus S4...............................................................


The type of class to use is the subject of some controversy among R program-
mers. In essence, your view here will likely depend on your personal choice
of which you value more—the convenience of S3 or the safety of S4.
John Chambers, the creator of the S language and one of the central
developers of R, recommends S4 over S3 in his bookSoftware for Data Anal-
ysis(Springer, 2008). He argues that S4 is needed in order to write “clear
and reliable software.” On the other hand, he notes that S3 remains quite
popular.
Google’s R Style Guide, which you can find athttp://google-styleguide
.googlecode.com/svn/trunk/google-r-style.html, is interesting in this regard. Google
comes down squarely on the S3 side, stating “avoid S4 objects and methods
when possible.” (Of course, it’s also interesting that Google even has an R
style guide in the first place!)

NOTE A nice, concrete comparison of the two methods is given in Thomas Lumley’s
“Programmer’s Niche: A Simple Class, in S3 and S4,”R News, April 1, 2004,
pp. 33–36.

9.4 Managing Your Objects.....................................................


As a typical R session progresses, you tend to accumulate a large number of
objects. Various tools are available to manage them. Here, we’ll look at the
following:


  • Thels()function

  • Therm()function

  • Thesave()function

  • Several functions that tell you more about the structure of an object,
    such asclass()andmode()

  • Theexists()function


9.4.1 Listing Your Objects with the ls() Function..........................


Thels()command will list all of your current objects. A useful named argu-
ment for this function ispattern, which enableswildcards. Here, you tellls()
to list only the objects whose names include a specified pattern. The follow-
ing is an example.

226 Chapter 9

Free download pdf