The technical term for magic is ”object orientation”. Object orientation is voluntary in R, and in fact there are two different versions of it in R. They are called — for historical reasons — S3 methods and S4 methods.

Need to know

As a user of R there is very little that you need to know about object orientation. The main point of object orientation is to make things easier for the user. You don’t need to memorize a lot of function names, you can merely use plot to get an appropriate picture for a wide range of types of objects.

The main way that object orientation can be a disadvantage is that print is a generic function so what is printed is not necessarily a precise representation of the actual object. To see what an outline of what an object really looks like, you can do:

> str(x)

Many objects with a class are really a list. You can see the names of that list with:

> names(x)

You can always see the true structure of an object with:

> print(unclass(x))

Resources

Circle 7 provides a cursory introduction to object orientation in R.

Back to top level of Impatient R

Kommentarer inaktiverade för More R Magic

See more

Explore more content and blog posts.

  • jun 25, 26

    Programmers think programming is really hard.  Non-programmers think it’s even harder than that. Figure 1: The perceived difficulty of programming.  Why is programming so arduous? […]

  • jun 25, 26

    Coordinates: 2014 September 15-17 in the London borough of #rstats. 15th, evening I had just the right number of R bugs so that I could walk to the drinks and arrive [...]

  • jun 25, 26

    Navigation gets you from where you are to where you want to be. Speaking of navigation, you can jump to selected sections of this post: Navigation; R-bloggers; Task views; Rdocumentation.org; [...]