Skip to content
Back to formatted view

Raw Message

Message-ID: <Pine.SOL.3.96.1030501134041.40A-100000@libra.cus.cam.ac.uk>
Date: 2003-05-01T12:56:23Z
From: Damon Wischik
Subject: Class troubles

I would appreciate some guidance about classes. I think I'm
getting confused about S3 classes and S4 classes, in the following:

--------------
library(lattice)
library(methods)
s <- shingle(1:5)
class (s)

# this reports that s has class "shingle", as expected

foo <- function(x) as.factor(x)
setGeneric("foo")
setMethod("foo","numeric",function(x) as.shingle(x))
setMethod("foo","shingle",function(x) {cat("A shingle!\n"); x})

# gives me a warning:
# Class "shingle" not defined in: matchSignature(signature, fdef)

foo(s)

# Calls the "foo" for shingle, as I want it to.
---------------------------

If I defined a "shingle" S4 class, I expect I wouldn't get the warning
message when I try to define "foo" for "shingle".  But I want my routine
to work with the existing shingle S3 class from the lattice package. 

My code works as it is, but I get the warning message, which makes me
uneasy. What should I do?

Damon Wischik.