From simon.urbanek at r-project.org  Sun Jan 23 21:23:23 2011
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Sun, 23 Jan 2011 15:23:23 -0500
Subject: [Rd] feature request: additional hook in plot.new()
In-Reply-To: <4D3C4CD5.30104@acm.org>
References: <4D3C4CD5.30104@acm.org>
Message-ID: <570CC602-46B1-47A3-A419-CF43E8DD2996@r-project.org>


On Jan 23, 2011, at 10:44 AM, Tony Plate wrote:

> 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.
> 

Just note on the latter: I would expect this to be usually better handled by the device/UI as you will be in conflict with things like plot history, already supported tabbed devices etc. Do you have a use case where the above has any benefits over separate devices in tabs? (The website has little detail so I'm just guessing what you're up to ..).

Cheers,
Simon



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