From maechler at stat.math.ethz.ch  Sat Jun 26 22:00:08 2004
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Sat Jun 26 22:00:15 2004
Subject: [Rd] Re: plot.new() warning from coplot()'s par(*, new=FALSE)
In-Reply-To: <x2lliay7eh.fsf@biostat.ku.dk>
References: <Pine.LNX.4.44.0406261811560.1421-100000@unix24.alpha.wehi.edu.au>
	<x2lliay7eh.fsf@biostat.ku.dk>
Message-ID: <16605.54728.73248.430943@gargle.gargle.HOWL>

{diverted from the R-SIG-gui list}

>>>>> "PD" == Peter Dalgaard <p.dalgaard@biostat.ku.dk>
>>>>>     on 26 Jun 2004 11:51:02 +0200 writes:

    PD> James Wettenhall <wettenhall@wehi.edu.au> writes:
    >> Hi,
    >> 
    >> Does anyone know a good way to get rid of warnings like:
    >> Warning message: calling par(new=) with no plot
    >> 
    >> when using an R plot function which calls plot.new()
    >> (e.g. coplot) from within tkrplot?
    >> 
       .....

    PD> Hmm, the same wart appears if you just plot to a freshly
    PD> opened X11 device (X11(); coplot(....)), nothing
    PD> specific to tkrplot. I think I've seen this reported
    PD> before, but I have forgotten what the recommended action
    PD> was.

If I look at coplot, I see that it's very first graphics call is

  par(mfrow =..................., new = FALSE)

and this ('new = FALSE') of course gives the warning when no
graphic device is active.
coplot()'s code  is just not quite right here IMO.

I can rid of the warning and keep coplot() behaving as
now otherwise by replacing

      opar <- par(mfrow = c(total.rows, total.columns),
                  oma = oma, mar = mar, xaxs = "r", yaxs = "r", new = FALSE)

by
      if(dev.cur() > 1 && par("new")) # turn off a par(new=TRUE) setting
          par(new = FALSE)
      opar <- par(mfrow = c(total.rows, total.columns),
                  oma = oma, mar = mar, xaxs = "r", yaxs = "r")

- - -

and I'd commit this (to R-patched).

OTOH, I wonder if we couldn't just omit the   
      if(...) par(new = FALSE)
clause {for R-devel at least}.
If a user really calls  par(new = TRUE) before calling coplot()
(s)he should be allowed to produce such a monstrosity --- unless
its an ingenuosity such as drawing a background image on which
to draw coplot() ...

Martin Maechler


[Rd] Re: plot.new() warning from coplot()'s par(*, new=FALSE)
Martin Maechler