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

John Chambers jmc at r-project.org
Wed Aug 8 10:51:47 CEST 2012


Good catch.  This should have been fixed in r-devel, revision 60192.  If 
nothing bad results in other tests, we'll port it to the current patched 
version.

Thanks,
   John

On 8/5/12 4:31 PM, Martin Morgan wrote:
> 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



More information about the R-devel mailing list