2

What command can I use to find and set plot window to maximum available, i.e. one that will produce a plot window as one gets after clicking on maximize button of top bar?

I searched and found that while running R on Windows one can use windows(width,height) function while on linux one can use X11.options(). One can also insert a line the file: ~/.Xresources: R_x11*geometry: 600x600 as suggested on this page.
However, I could not find how to get maximum size possible on the computer where the program is run and what is the best way to set the plot window to the maximum size using R commands.

Community
  • 1
  • 1
rnso
  • 23,686
  • 25
  • 112
  • 234
  • Inspired by @lukeA's post, I found [this related post](http://stackoverflow.com/q/7305244/489704). – jbaums Jun 18 '14 at 10:00

2 Answers2

1

On windows, I'd try getting the screen resolution on dpi first, then set the width/height parameters accordingly:

windowsMax <- function() {
  f <- function(cmd) as.numeric(gsub("\\D", "", system(cmd, intern=TRUE)[2]))
  width <- f("wmic desktopmonitor get screenwidth")
  height <- f("wmic desktopmonitor get screenheight")
  dpi <- f("wmic desktopmonitor get PixelsPerXLogicalInch")
  windows(width = width / dpi, height = height / dpi)
}
windowsMax()
lukeA
  • 53,097
  • 5
  • 97
  • 100
  • The plot window is nowhere to be seen for me (but shows in the taskbar). Width and height both return `NA` - Win 8.1. :( – jbaums Jun 18 '14 at 09:58
  • It seems to get it to work I need to use the 3rd element of the returned vector: `system(cmd, intern=TRUE)[3])`. Strangely, the window doesn't cover the entire screen, despite the returned width and height being correct. – jbaums Jun 18 '14 at 10:02
  • Strange. I'm on Windows 7 x64, however, I don't get a fully maximized window, too. Don't know if this is possible... – lukeA Jun 19 '14 at 07:30
  • Yes, this doesn't work for me on W8/W8.1. The results for the commands to show the width and height are empty when run in the cmd window. I think its something to do with a different DOS version (I read something or other on this a month or 2 ago) – user20650 Jun 19 '14 at 16:19
0

This seems to work 'ok' on Ubuntu 12.04. [I got most details from a post on Rhelp (i think) some time ago]

my.dev.new <- function() { 

  scrn <- system("xdpyinfo  | grep 'dimensions:'", wait=FALSE, intern=TRUE)
  sc.dim <-  as.numeric(unlist(regmatches( scrn, regexec("(\\d+)x(\\d+)",  
                                                                  scrn) ))[-1])

  res <- system("xdpyinfo  | grep 'resolution:'", wait=FALSE, intern=TRUE)
  dpi <-  as.numeric(unlist(regmatches( res, regexec("(\\d+)x(\\d+)",  res) ))[-1])

  wdth <- sc.dim[1]/ dpi[1]
  ht <- sc.dim[2] / dpi[2]
  dev.new(width = wdth, height = ht)
}


my.dev.new()
user20650
  • 24,654
  • 5
  • 56
  • 91
  • 1
    This is exactly what I wanted. I also noted that putting large numbers in command dev.new(width=30, height=30) also produces maximized window. – rnso Jun 19 '14 at 09:52