[R] Class troubles
Damon Wischik
djw1005 at cam.ac.uk
Thu May 1 14:56:23 CEST 2003
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.
More information about the R-help
mailing list