[Rd] setMethod sometimes fails to set package slot when signature has trailing 'ANY'

Martin Morgan mtmorgan at fhcrc.org
Mon Aug 6 01:31:47 CEST 2012


after this

   setClass("A")

   setGeneric("bar", function(x, y) standardGeneric("bar"))
   setMethod(bar, signature(x="A", y="A"), function(x, y) {})
   setMethod(bar, signature(x="A", y="ANY"), function(x, y) {})

the method for signature c("A", "A") contains package information

 > str(getMethod(bar, c("A", "A")))
Formal class 'MethodDefinition' [package "methods"] with 4 slots
   ..@ .Data  :function (x, y)
   ..@ target :Formal class 'signature' [package "methods"] with 3 slots
   .. .. ..@ .Data  : chr [1:2] "A" "A"
   .. .. ..@ names  : chr [1:2] "x" "y"
   .. .. ..@ package: chr [1:2] ".GlobalEnv" ".GlobalEnv"
   ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
   .. .. ..@ .Data  : chr [1:2] "A" "A"
   .. .. ..@ names  : chr [1:2] "x" "y"
   .. .. ..@ package: chr [1:2] ".GlobalEnv" ".GlobalEnv"
   ..@ generic: atomic [1:1] bar
   .. ..- attr(*, "package")= chr ".GlobalEnv"

but the method for signature c("A", "ANY") does not

 > str(getMethod(bar, c("A", "ANY")))
Formal class 'MethodDefinition' [package "methods"] with 4 slots
   ..@ .Data  :function (x, y)
   ..@ target :Formal class 'signature' [package "methods"] with 3 slots
   .. .. ..@ .Data  : chr [1:2] "A" "ANY"
   .. .. ..@ names  : chr [1:2] "x" "y"
   .. .. ..@ package: chr [1:2] "" ""
   ..@ defined:Formal class 'signature' [package "methods"] with 3 slots
   .. .. ..@ .Data  : chr [1:2] "A" "ANY"
   .. .. ..@ names  : chr [1:2] "x" "y"
   .. .. ..@ package: chr [1:2] "" ""
   ..@ generic: atomic [1:1] bar
   .. ..- attr(*, "package")= chr ".GlobalEnv"

This does not occur when the order of setMethod calls is reversed. The 
reason is that the package information added when 
methods/R/Methods.R:552 calls matchSignature are stripped (because 
matchSignature returns a vector with trailing 'ANY' classes removed) by 
the call to .matchSigLength at line 603.

The context for this is the thread starting at

https://stat.ethz.ch/pipermail/bioconductor/2012-August/047241.html

where a complicated package dependency and attempt to redefine an 
existing method leads to

Error : package slot missing from signature for generic 'sampleNames<-'
and classes LumiBatch, ANY
cannot use with duplicate class names (the package may need to be 
re-installed)

Martin
-- 
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793



More information about the R-devel mailing list