Wednesday, September 28, 2011

For Linux / MacOS users: Easy fix for windows() command

For users of Linux / MacOS, the windows() command in R is not recognized. The analogous command is X11(). Therefore, you could go through the programs and replace every occurrence of windows(...) with X11(...). Or, you could just tell R to do it for you, by putting this line at the top of the file (but after any remove all objects command):

if ( .Platform$OS.type != "windows" ) { 
   windows <- function( ... ) X11( ... ) 

This tip was suggested by George Kachergis. Thanks George!

See additional graphics info at this more recent blog entry.


Anonymous said...

Actually if you just change windows() to throghout your code, it will be platform independent.

John K. Kruschke said...

Dear Anonymous December 23:

Great tip; thank you! Works fine, apparently, when using the basic R editor and command console.

But, unfortunately it does not work in RStudio for multiple plots (as I often use):

Error in function () : Only one RStudio graphics device is permitted

The RStudio Support page has several people asking about this problem, and the replies from the RStudio folks say that eventually they'd like to get multiple devices implemented.

Thank you again.