From Martin Maechler <maechler@stat.math.ethz.ch>  Thu Jun 25 07:46:32 1998
From: Martin Maechler <maechler@stat.math.ethz.ch> (Martin Maechler)
Date: Thu, 25 Jun 1998 08:46:32 +0200
Subject: Warning in par(args) -- the(?) solution
In-Reply-To: <x2vhprt8ke.fsf@blueberry.kubism.ku.dk> (message from Peter
 Dalgaard BSA on 24 Jun 1998 12:09:37 +0200)
Message-ID: <199806250646.IAA27094@sophie.ethz.ch>

>>>>> "PD" == Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk> writes:

    PD> Martin Maechler <maechler@stat.math.ethz.ch> writes:

      MM>   on.exit(par(op))
      MM>   op <- par(xyx = ...,  brd = ...)
      MM>   work.work2()
      MM>   op <- c(op, par(ghj = ...,  klm = ...))
      MM>   work.work3()
      MM> ...

      MM> Therefore, a later par(op) [called by on.exit(.)] only calls par(.)
      MM> with arguments that make sens to be changed.

    PD> Yup, but as has been pointed out there's a problem: If you change the
    PD> same parameter twice, you actually get the wrong result:

    >> opar<-par(cex=2)
    >> opar<-c(opar,par(cex=4))
    >> par(opar)
    >> par()$cex
    PD> [1] 2

    PD> which happens because

    >> opar
    PD> $cex
    PD> [1] 1

    PD> $cex
    PD> [1] 2

    PD> and par() sets parameters in the order it finds them. Of course one
    PD> could get the first item of each name by using

    >> opar[unique(names(opar))]
    PD> $cex
    PD> [1] 1

    PD> or let par(opar) do that internally, but I'm not sure that it is
    PD> really such a good idea.

Wouldn't the ``easy'' solution be 
to use a FILO instead of a FIFO stack :

      >   on.exit(par(op))
      >   op <- par(xyx = ...,  brd = ...)
      >   work.work2()
      >   op <- c(par(ghj = ...,  klm = ...), op) ##--- PREPEND new par() --- !
	                                    #####
      >   work.work3()
      > ...

Of course this also depends on the (current) behavior of par() 
	(``setting parameters in the order it finds them''),
but we could "standardize" par() that way ((and document it!)) 
(and it is S compatible ..).

Martin



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


Warning in par(args) -- the(?) solution
Martin Maechler