[R-sig-Geo] C API for sp classes?
Tim Keitt
tkeitt at mail.utexas.edu
Tue Mar 7 17:55:13 CET 2006
On Tue, 2006-03-07 at 16:24 +0000, Barry Rowlingson wrote:
> Wouter Buytaert wrote:
>
> > The resulting R function doesn't seem very complicated. I'm a newbie
> > though, so all recommendations welcome:
> >
> > topidx <- function(map) {
> >
> > if(!(class(map) == "SpatialGridDataFrame"))
> > printf("Map should be of SpatialGridDataFrame class")
> >
>
> Recommendation number 1 - read all about Object-Oriented Programming!
>
> You shouldn't have a function that tests the class of an object, you
> should write a generic function and a method for your class.
That's a rather odd aspect of S methods -- even if you only want to call
the function for a single class, you have to create a generic function.
In cases where I'm not wanting polymorphic behavior (the function really
only makes sense for a single class), I tend to write ordinary functions
and either test for class membership or just document that the passed
object should be of the appropriate class. When the function will be
called on multiple classes, then it is worth defining a generic
function. Making everything generic is too much overhead.
THK
--
Timothy H. Keitt
Assistant Professor
http://www.keittlab.org/
http://www.utexas.edu/directory/index.php?q=Keitt
More information about the R-sig-Geo
mailing list