-----Oorspronkelijk bericht-----
Van: Martin Morgan [mailto:mtmorgan at fhcrc.org]
Verzonden: vrijdag 11 maart 2011 7:36
Aan: ONKELINX, Thierry
CC: r-devel at r-project.org; John Chambers
Onderwerp: Re: [Rd] Problem with defining new method for residuals()
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.
Error in object$na.action : $ operator not defined for this S4 class
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 at Residual } )
setMethod("resid", signature(object = "AFLP.outlier"),
function(object, ...){ object at Residual } )
----------------------------------------------------------------------
Instituut voor natuur- en bosonderzoek team Biometrie &
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.Onkelinx at 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:
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
not ensure that a reasonable answer can be extracted from a