[Rd] feature request: additional hook in plot.new()

Tony Plate tplate at acm.org
Sun Jan 23 16:44:21 CET 2011


Request: An additional hook in plot.new() that is called prior to the call to .Internal(plot.new()).
Reason: To allow the hook to set up or modify a graphics device that the new plot will appear in.

The code change needed for this is simple - just 4 new lines of R code in src/library/graphics/R/plot.R:plot.new()

Current definition of plot.new() in src/library/graphics/R/plot.R:

plot.new <- function()
{
     .Internal(plot.new())
     for(fun in getHook("plot.new")) {
         if(is.character(fun)) fun <- get(fun)
         try(fun())
     }
     invisible()
}

New definition of plot.new() in src/library/graphics/R/plot.R:

plot.new <- function()
{
     for(fun in getHook("plot.prenew")) {
         if(is.character(fun)) fun <- get(fun)
         try(fun())
     }
     .Internal(plot.new())
     for(fun in getHook("plot.new")) {
         if(is.character(fun)) fun <- get(fun)
         try(fun())
     }
     invisible()
}

In src/library/graphics/man/frame.Rd after the existing sentence beginning "There is a hook..." in the DETAILS section, the following sentence could be added:

"There is another hook called \code{"plot.prenew"} which is called before advancing the frame.  This hook can be used to create a new plot "

The name of the hook is not very important -- I've suggested "plot.prenew" here.  Another possibility could be "plot.new0".

More detail on the reason:

In a tabbed graphics widget (https://r-forge.r-project.org/projects/tabbedplots/ ), having this hook would enable it to operate in a mode where a new tab is automatically created for each new plot.

thanks for your consideration,

Tony Plate



More information about the R-devel mailing list