Hi

I am having difficulty defining an S4 method for head() and tail().

I can't quite provide minimal self-contained code
because the problem appears to require the whole corpus
of my package; and there also appears to be a difference
between sourcing the lines directly, and having them
installed in a package.

The lines in question (I think) are:

setClass("mdm",
        representation = representation(
          xold  = "matrix",
          types = "factor"
          )
        )

"mdm" <- function(xold, types){
 new("mdm", xold=xold, types=types)
}

setGeneric("head",function(x,...){standardGeneric("head")})
setMethod("head",signature="mdm",function(x,n=6,...){
 mdm(head(x...@xold,n=n,...) , types=factor(head(x...@types,n=n,...)))
} )


If the above lines are part of the package source, and I install the package
then sometimes  I get errors like

> head(toy_mm())
Error in function (classes, fdef, mtable)  :
unable to find an inherited method for function "head", for signature "matrix"
>

and sometimes it works as desired.

Why should head() not be able to take the first few lines of a matrix?
It seems to be "forgetting" that head.matrix() exists.

Can anyone give me some pointers for debugging this problem?

rksh







--
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to