[R] Substituting a user-defined function for a standard function in graphics
John Kolassa
kolassa at stat.rutgers.edu
Wed Jul 15 22:25:33 CEST 2009
Dear R-help readers,
I'm trying to substitute my own version of plot.default, in order to
capture low-level graphics input for further manipulation. I seem to be
having difficulties getting the versions of functions that I intend to use
called at the right places.
Specifically, I have an object produced by survfit from the survival
package, and I want to save the values that plot.survfit would normally
send to plot.default from the graphics package. I've tried the following:
1. I put my version of plot.default into .GlobalEnv. This works, in the
sense of running without an error, but doesn't do what I want, since my
version of plot.default never gets called, apparently because since the
version of plot comes from graphics, the graphics namespace takes
precedence over .GlobalEnv.
2. I put both my version of plot.default, and a copy of plot from graphics
(with a browser call on top, so that I know it's my version), into
.GlobalEnv. In this case, I get an error, apparently because my version of
plot hits the line UseMethod("plot"), can't see the survfit method, and so
the fit gets dumped to plot.default, plot.default can only handle
arguments as defined in the graphics documentation on xy.coordinates, and
survfit isn't in this format. I can't figure out why UseMethod("plot")
doesn't send the survfit object to plot.survfit. methods("plot") gives
survfit with an asterisk (denoting invisibility); is the invisibility a
problem?
3. I made a package incorporating the graphics plot and my plot.default,
without a namespace file, and loaded it via a library call. This again
gave me an error, since the survfit object seems to be sent directly to
plot.default rather than plot.survfit.
4. I made a package incorporating the graphics plot and my plot.default,
this time with a namesapce file that exports plot and plot.default. This
again gave me the same error, since the survfit object seems to be sent
directly to plot.default rather than plot.survfit.
I read the document Writing R Extensions, but wasn't able to solve this
problem. Any pointers would be greatly appreciated.
Thanks, John Kolassa
More information about the R-help
mailing list