Skip to content
Back to formatted view

Raw Message

Message-ID: <49D7473B.6030909@dbmail.com>
Date: 2009-04-04T11:40:43Z
From: Romain Francois
Subject: temporarily modify par values?
In-Reply-To: <87hc14brh8.fsf@lse.ac.uk>

Jim Ottaway wrote:
> Is there some sort of 'with.par' function that temporarily changes par
> parameters and then re-sets them so that instead of doing things such as
>
> opar <- par(mar=c(4.1,4.1,4.1,8),...)
>
> <do things>
>
> par(opar)
>
> you can do something like
>
> with.par(mar=c(4.1,4.1,4.1,8),..., 
>     <do things>)
>
> where all but the last argument are parameters for par, and the last is
> evaluated with opar <- par(...) and par(opar) wrapped around it?
>
> Yours sincerely,
>   
Hi,

"with" is generic, so you could do something like that:

 > par <- function( ... ) structure( graphics::par( ... ), class = "par" )
 > with.par <- function( data, expr, ... ){
+    old.par <- data
+    expr
+    invisible( par( old.par ) )
+ }
 > with( par( mar = c(0,0,0,0) ), plot( 1:10, 1:10 ) )
 > plot( 1:10, 1:10)

Romain

-- 
Romain Francois
Independent R Consultant
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr