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

Gabor Grothendieck ggrothendieck at gmail.com
Sun Aug 17 19:50:13 CEST 2008

In that case add this:

unlockBinding("strucplot", as.environment("package:vcd"))
assign("strucplot", my.strucplot, "package:vcd")

On Sun, Aug 17, 2008 at 1:22 PM, Ben Bolker <bolker at ufl.edu> wrote:
> 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
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

More information about the R-help mailing list