[Rd] Namespaces and S4 Generics

Roger Koenker rkoenker at illinois.edu
Fri Jul 11 20:27:56 CEST 2014

I've installed R-devel

R Under development (unstable) (2014-07-09 r66111)
Platform: x86_64-apple-darwin13.1.0 (64-bit)

and am trying to resolve some problems that I am seeing with my 
SparseM package.  In prior versions I explicitly had:

setGeneric("image", function(x, ...) standardGeneric("image"))

and then used setMethod to define a method for the class matrix.csr
but my reading of the setGeneric manpage suggests that this call to
setGeneric need not, and probably should not have this second 
argument, and indeed, need not exist at all, since the generic is
automatically created by the setMethod invocation.

However,  what is puzzling to me is that in my new R-devel version
none of these options have the intended effect of making "image"
a generic and allowing R to dispatch for matrix.csr objects.  When
I omit the setGeneric() call, I do get a message at INSTALL time
that a generic for image is being created, but then after loading

> showMethods(image)
Function "image":
<not an S4 generic function>

On the command line, I can make this work:

> setGeneric("image")
[1] "image"
> showMethods(image)
Function: image (package graphics)

And -- even more irritating --  if I  require(Matrix)  then the generic
is created together with my method and all the Matrix methods.  At 
the risk of theorizing without data, I suspect that this has something
to do with NAMESPACES, and I have tried to follow the setup for
Matrix by having:

importFrom("graphics", image)

but clearly I'm still missing some crucial aspect.  Any suggestions
would be most welcome.


url:    www.econ.uiuc.edu/~roger            Roger Koenker
email    rkoenker at uiuc.edu            Department of Economics
vox:     217-333-4558                University of Illinois
fax:       217-244-6678                Urbana, IL 61801

More information about the R-devel mailing list