Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

platform neutral call for new plot

Tags:

r

I have a function that calls multiple windows (new graphics device window). To make this happen I use windows(). This works but as this is for a package how do I make it platform neutral so each plot gets plotted in a new window while leaving the old window?

What I currently have:

WORD.C <- function(WORDS){
require(wordcloud)

L2 <- lapply(WORDS, function(x) as.data.frame(table(x), stringsAsFactors = FALSE))

    FUN <- function(X){
        windows()  #how to make this platform neutral
        wordcloud(X[, 1], X[, 2], min.freq=1)
    }
    lapply(L2, FUN)
}

WORD.C(list.xy)
like image 691
Tyler Rinker Avatar asked May 08 '26 23:05

Tyler Rinker


2 Answers

Will dev.new() cover your needs? It opens a graphics window of the default type set up in your console sessions.

like image 97
Carl Witthoft Avatar answered May 10 '26 12:05

Carl Witthoft


The Mac will generally open up an X11 window, so this might be a minimal solution:

if( .Platform$OS.type =="unix" ) { X11() } else { windows() }

If you want to branch on the GUI type then you could use:

if( .Platform$GUI %in% ("X11", "Tk") ) { X11() } else { 
      if ( .Platform$GUI == "AQUA" ){ quartz()} else {
             windows()                            }     }
# For more details
?.Platform
?Devices
like image 45
IRTFM Avatar answered May 10 '26 14:05

IRTFM