Skip to content
Prev 17206 / 63424 Next

Registering S3 class from external package

Your description is a bit too vague to be sure, but it sounds as if 
you're trying to do something that breaks the basic namespace idea.
Paul Roebuck wrote:

            
Dispatch from where?  If you mean from a generic function inside your 
package's namespace, then the corresponding class definitions need to be 
defined in or imported into that namespace when it's constructed.  One 
of the main virtues of the namespace mechanism is that the known classes 
(& therefore the dispatch behavior) are fixed by the package source + 
its imports.  This means that the behavior of the package is insulated 
against effects from attaching other packages.

OTOH, if you mean dispatch from a generic function in the global 
environment or another (non-NAMESPACE) package, then you need to ensure 
that the setOldClass() takes place in the appropriate environment; e.g. 
if the generic is in the global environment,
   setOldClass(c("foo", "bar"), where = .GlobalEnv)
If you're dispatching from a generic in "somepkg", the setOldClass call 
should just be a part of the source for that package.
But, again, these will not help if you're dispatching from the mypkg 
namespace; that's just what the mechanism is trying to avoid.

In case it's not clear, the setOldClass() call defines a special kind of 
  S4 class for each of the S3 classes.  Therefore it's subject to the 
same locking rules as setClass() or any other call that needs to do an 
assignment as a side effect.