Skip to content
Prev 47910 / 63424 Next

Conflicting definitions for function redefined as S4 generics

I haven't looked at this in detail, but my guess is the following is the 
distinction:

A simple call setGeneric("sort") makes a generic of the existing 
function _with the existing package_:

 > setGeneric("sort")
[1] "sort"
 > sort
standardGeneric for "sort" defined from package "base"

function (x, decreasing = FALSE, ...)
standardGeneric("sort")
<environment: 0x7fdf74335640>
Methods may be defined for arguments: x, decreasing
Use  showMethods("sort")  for currently available ones.

The same thing will, I believe, happen automatically if one calls 
setMethod() without a prior call to setGeneric().

What BioGenerics does is different:  it excludes the two trailing 
arguments and so creates a new generic in its own namespace.

Similarly (from the global environment in this case):

 > setGeneric("sort", signature="x")
Creating a new generic function for 'sort' in the global environment
[1] "sort"
 > sort
standardGeneric for "sort" defined from package ".GlobalEnv"

function (x, decreasing = FALSE, ...)
standardGeneric("sort")
<environment: 0x7fd33b21bb78>
Methods may be defined for arguments: x
Use  showMethods("sort")  for currently available ones.


When packages are loaded, the methods in the new package are installed 
in the generic function (in memory) that corresponds to the information 
in the methods as to generic name and package slot.

As Duncan points out, it's essential to keep functions of the same name 
but different packages distinct.  Like all R objects, generic functions 
are referred to by the combination of a name and an environment, here a 
package namespace.

Just how this sorts out into the symptoms reported I can't say, but I 
suspect this is the underlying issue.

John
On 3/26/14, 7:11 AM, Ulrich Bodenhofer wrote: