[R] Injecting code in a package?

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jan 28 15:28:47 CET 2011

On Fri, Jan 28, 2011 at 8:57 AM, Nick Sabbe <nick.sabbe at ugent.be> wrote:
> Dear list,
> I've had this a few times now, and wonder if this is possible:
> I'm using a package, often for plotting something, but I want to tune the
> way the plotting goes, in a way that was not foreseen by the maker of the
> package.
> Now, most of the time, these kinds of R functions (say pkg::plot.something)
> call into other R functions (say pkg::plot.something.internal), and it is
> these that I want to tinker with.
> So, my question is: can I replace an R function in a package with  a version
> of my own, without having to somehow rebuild the package? I don't just want
> a non-package bound copy of the function, I want to make sure that when I
> call pkg::plot.something, this works as before, but when, from within this
> function, pkg:: plot.something.internal is called, I want it to call _my_
> version of it.

Note that there is a hook available for plotting which may be
sufficient if the real application is just plot and you need to
intercept it at the hooked spot.  See ?plot.new

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

More information about the R-help mailing list