Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the screen resolution in R

How can I get screen resolution (height, width) in pixels?

like image 413
George Dontas Avatar asked Sep 05 '11 07:09

George Dontas


1 Answers

You could use commad-line interface to WMI

> system("wmic desktopmonitor get screenheight")
ScreenHeight  
900   

You could capture result with system

(scr_width <- system("wmic desktopmonitor get screenwidth", intern=TRUE))
# [1] "ScreenWidth  \r" "1440         \r" "\r"
(scr_height <- system("wmic desktopmonitor get screenheight", intern=TRUE))
# [1] "ScreenHeight  \r" "900           \r" "\r" 

With multiple screens, the output is, e.g.,

[1] "ScreenWidth  \r" "1600         \r" "1600         \r" ""

We want all but the first and last values, converted to numbers

as.numeric(c(
  scr_width[-c(1, length(scr_width))], 
  scr_height[-c(1, length(scr_height))]
))
# [1] 1440  900
like image 196
Marek Avatar answered Oct 18 '22 18:10

Marek