On 03/10/2011 08:21 AM, ONKELINX, Thierry wrote: > Dear all, > > I'm writing a package and I would like to reuse the residuals() > function. When I use a function which calls the redefined residuals > (for my custom class) I get an error (see below). It looks like the > wrong method is used. The strange this is, that when it execute the > code manually it get no error.
Hi Thierry -- I think this is a bug in the methods package. Your package promotes stats::residuals to an S4 generic. Normally this should work. However, your package Depends: on lme4, which also promotes stats::residuals to an S4 generic. Apparently, this interferes with your own attempt to make a generic, even though you do not import lme4 into your name space. As a consequence of the (putative) bug, your package sees the original stats::residuals. A work-around seems to be to importFrom(lme4, residuals) and do NOT import residuals from stats, so that your own method is associated with the generic defined in lme4. Martin > > Any suggestions? > > Best regards, > > Thierry > > The entire source code is at > svn://scm.r-forge.r-project.org/svnroot/aflp > > The code with the error. > >> normalise(dummy) > Error in object$na.action : $ operator not defined for this S4 class >> traceback() > 5: naresid(object$na.action, object$residuals) at normalise.R#30 4: > residuals.default(outliers(data)) at normalise.R#30 3: > residuals(outliers(data)) at normalise.R#30 2: > nrow(residuals(outliers(data))) at normalise.R#30 1: > normalise(dummy) #This works fine >> data <- dummy nrow(residuals(outliers(data))) > [1] 0 > > NAMESPACE importFrom(stats, residuals, resid, hclust, princomp) > exportPattern(".") > > METHODS setMethod("residuals", signature(object = "AFLP.outlier"), > function(object, ...){ object@Residual } ) > > setMethod("resid", signature(object = "AFLP.outlier"), > function(object, ...){ object@Residual } ) > > ---------------------------------------------------------------------------- > > ir. Thierry Onkelinx > Instituut voor natuur- en bosonderzoek team Biometrie & > Kwaliteitszorg Gaverstraat 4 9500 Geraardsbergen Belgium > > Research Institute for Nature and Forest team Biometrics & Quality > Assurance Gaverstraat 4 9500 Geraardsbergen Belgium > > tel. + 32 54/436 185 thierry.onkel...@inbo.be www.inbo.be > > To call in the statistician after the experiment is done may be no > more than asking him to perform a post-mortem examination: he may be > able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher > > The plural of anecdote is not data. ~ Roger Brinner > > The combination of some data and an aching desire for an answer does > not ensure that a reasonable answer can be extracted from a given > body of data. ~ John Tukey > > ______________________________________________ R-devel@r-project.org > mailing list https://stat.ethz.ch/mailman/listinfo/r-devel -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793 ______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel