Re: [R] Derived classes

2008-09-04 Thread Gabor Grothendieck
Try this: # constructor for Square makeSquare <- function(name, side) structure(list(name = name, side = side), class = c("Square", "Shape")) # generic getName <- function(shape) UseMethod("getName") # Shape method getName.Shape <- function(shape) shape$name # generic getArea <- function(shape)

[R] Derived classes

2008-09-04 Thread rkevinburton
Coming from a C++ and C# background I would like to know how inheritance works with 'R'. The classical example is I can define an abstract class 'Shape' and have an array of 'Shape's but each instance could be a Circle, Square, Triangle, etc. because they all derive from 'Shape'. At runtime if I