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

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 25 Jun 1998 08:46:32 +0200


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