[Rd] Problem with defining new method for residuals()

ONKELINX, Thierry Thierry.ONKELINX at inbo.be
Thu Mar 10 17:21:12 CET 2011

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.

Any suggestions?

Best regards,


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

importFrom(stats, residuals, resid, hclust, princomp)

setMethod("residuals", signature(object = "AFLP.outlier"), 
	function(object, ...){
		object at Residual

setMethod("resid", signature(object = "AFLP.outlier"), 
	function(object, ...){
		object at Residual

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie & Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen

Research Institute for Nature and Forest
team Biometrics & Quality Assurance
Gaverstraat 4
9500 Geraardsbergen

tel. + 32 54/436 185
Thierry.Onkelinx at 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

More information about the R-devel mailing list