[R] How do I change which R Graphics Device is active?

Don MacQueen macq at llnl.gov
Wed Jul 1 16:30:03 CEST 2009


My version would be

   newDev <-  function() { dev.new(); invisible( dev.cur() ) }

I agree with Hadley that return() is redundant in this instance. 
Using invisible() suppresses automatic printing of the returned value 
when it is not being assigned to a variable, thus making it more like 
dev.new().

While we're at it, consider

   newDev <-  function(...) { dev.new(...); invisible( dev.cur() ) }

which should allow one to pass through optional arguments (which only 
makes sense if they're valid for dev.new(), of course).

-Don

At 7:18 PM -0500 6/30/09, hadley wickham wrote:
>On Tue, Jun 30, 2009 at 2:12 PM, Barry
>Rowlingson<b.rowlingson at lancaster.ac.uk> wrote:
>>  On Tue, Jun 30, 2009 at 8:05 PM, Mark Knecht<markknecht at gmail.com> wrote:
>>
>>>  You could wrap it in a function of your own making, right?
>>>
>>>  AddNewDev = function() {dev.new();AddNewDev=dev.cur()}
>>>
>>>  histPlot=AddNewDev()
>>>
>>>  Seems to work.
>>
>>   You leaRn fast :) Probably better style is:
>>
>  >  newDev = function(){dev.new();return(dev.cur())}
>>
>>   - which returns the value explicitly with return().
>
>R isn't C! ;)  I'd claim idiomatic R only uses return for special
>cases (i.e. when you can terminate the function early)
>
>Hadley
>
>--
>http:// had.co.nz/
>
>______________________________________________
>R-help at r-project.org mailing list
>https:// stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide http:// www. R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA
925-423-1062




More information about the R-help mailing list