I think the error is because the other functions are expecting the plot.new
function to do some specific things to set up the graphics device for a new
plot, but your function did not do those things.

You might consider the trace function as an alternative to what you are
trying.  It can be used to insert additional code into existing functions,
or replace them altogether.


On Tue, Dec 11, 2012 at 12:32 PM, John Kolassa <kolassa@stat.rutgers.edu>wrote:

> I am trying to get a function written in R that calls a cascade of
> functions from the graphics package, and I want to eventually call
> replacements to functions in the graphics package instead of the originals.
>  Specifically, I have a function that calls qqnorm in stats, which calls
> qqnorm.default in stats, which calls plot in graphics, which calls
> plot.default and plot.new, and I want my own functions plot.default and
> plot.new that I entered at the command line (which I guess means that it is
> in .GlobalEnv).  I'd like my plot.default and plot.new called (this
> afternoon, at least) in place of every invocation of plot.default and
> plot.new resp..  So far I've tried:
>
> reassignInPackage from R.utils:
> reassignInPackage("plot.default","graphics",my.plot.default) gives "Error
> in assignInNamespaceT(name, value, ns = pkgName, envir = env) :   locked
> binding of ‘plot.default’ cannot be changed", even after
> unlockBinding("plot.default",as.environment("package:graphics"))
>
> assignInNamespace seems to almost work.  Here's what I enter:
>
> plot.default<-function(...){cat("Entered plot.default")}
> plot.new<-function(...){cat("Entered plot.new")}
> assignInNamespace("plot.default",plot.default,ns="graphics")
> assignInNamespace("plot.new",plot.new,ns="graphics")
> qqnorm(1:10)
>
> and here's what I get:
>
> Entered plot.newError in plot.xy(xy, type, ...) : plot.new has not been
> called yet
>
> It seems as though my new plot.new is being called, but the existing
> plot.default is being called, even though the new version is in
> graphics::plot.default.  I conjecture that this is because the original
> plot.default got exported when the package loaded, but is there a
>  way to overwrite this?  Thanks, John
>
> ______________________________________________
> R-help@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.
>



-- 
Gregory (Greg) L. Snow Ph.D.
538280@gmail.com

	[[alternative HTML version deleted]]


