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

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Sun, 05 Aug 2012 16:31:47 -0700


ink1">ink1">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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sun 05 Aug 2012 - 23:34:11 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 Wed 08 Aug 2012 - 11:20:38 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