[R] how to override/replace a function in a package namespace?

Ben Bolker bolker at ufl.edu
Sun Aug 17 19:22:42 CEST 2008


Gabor Grothendieck <ggrothendieck <at> gmail.com> writes:

> 
> Check out:
> 
> ?assignInNamespace
> 
> On Sun, Aug 17, 2008 at 12:42 PM, Michael Friendly wrote:
> > I'm trying to test an extension of mosaic() from the vcd package that
> > requires a change to the
> > basic strucplot() function from that package.  I want to test my change by
> > sourcing the
> > replacement function into my R session.
> >

  Yes, but:

from the note in ?assignInNamespace

assignInNamespace and fixInNamespace change the copy in the namespace,
 but not any copies already exported from the namespace, in particular 
an object of that name in the package (if already attached) and any 
copies already imported into
other namespaces. They are really intended to be used only 
for objects which are
not exported from the namespace. They do attempt to alter 
a copy registered as
an S3 method if one is found. 

  So if strucplot is exported from the vcd namespace (which I guess
it is), this won't work.

  When I ran into a similar situation recently I couldn't find any
solution other than rebuilding the package with my changes.

  Ben Bolker



More information about the R-help mailing list