Michael Friendly
2008-Aug-17 16:42 UTC
[R] how to override/replace a function in a package namespace?
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. But when I do that, source("c:/R/mosaics/strucplot-MF.R") and run my extension, it is apparent that it is vcd:::strucplot that is eventually called, not my replacement. Thus, I'm looking for something with the semantics and effect of source("c:/R/mosaics/strucplot-MF.R", namespace="vcd") that would replace the package version with my testing one. This question may have come up before, but searching the usual sources hasn't turned up anything useful. -Michael -- Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology Dept. York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html Toronto, ONT M3J 1P3 CANADA
Gabor Grothendieck
2008-Aug-17 17:07 UTC
[R] how to override/replace a function in a package namespace?
Check out: ?assignInNamespace On Sun, Aug 17, 2008 at 12:42 PM, Michael Friendly <friendly at yorku.ca> 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. > > But when I do that, > source("c:/R/mosaics/strucplot-MF.R") > and run my extension, it is apparent that it is vcd:::strucplot that is > eventually called, not > my replacement. Thus, I'm looking for something with the semantics and > effect of > source("c:/R/mosaics/strucplot-MF.R", namespace="vcd") > that would replace the package version with my testing one. > > This question may have come up before, but searching the usual sources > hasn't turned up anything > useful. > > -Michael > > -- > Michael Friendly Email: friendly AT yorku DOT ca Professor, Psychology > Dept. > York University Voice: 416 736-5115 x66249 Fax: 416 736-5814 > 4700 Keele Street http://www.math.yorku.ca/SCS/friendly.html > Toronto, ONT M3J 1P3 CANADA > > ______________________________________________ > 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. >