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

From: John Chambers <jmc_at_r-project.org>
Date: Wed, 08 Aug 2012 01:51:47 -0700

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



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 08 Aug 2012 - 09:01:37 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 09 Aug 2012 - 11:30:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive