[Rd] S4 and head() problems

From: Robin Hankin <rksh1_at_cam.ac.uk>
Date: Thu, 03 Dec 2009 11:04:03 +0000


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:


         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_at_xold,n=n,...) , types=factor(head(x_at_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?


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

R-devel_at_r-project.org mailing list
Received on Thu 03 Dec 2009 - 11:15:14 GMT

This archive was generated by hypermail 2.2.0 : Thu 03 Dec 2009 - 18:50:57 GMT