How do you get the title bar of a graphic device window?

You can set the title bar of a graphic device using

windows(title = "The title") #or equivalently x11(title = "The title") 

How do you retrieve a title from a graphics device window?

names(dev.cur()) , attributes(dev.cur()) , str(dev.cur()) and unclass(dev.cur()) do not show anything useful.

+7
source share
2 answers

It is not possible to call the window property due to device properties.

Under the windows you can try a mess with names(getWindowsHandles()) which gives me:

 > names(getWindowsHandles()) [1] "R Console" [2] "The title (ACTIVE)" [3] "R Information" 

eg. for the active device grep("\\(ACTIVE\\)$", names(getWindowsHandles()), value=TRUE) return the title.


It was easier than I thought:

 getTitle <- function(dev=dev.cur()) { all_pointers <- getWindowsHandles(which="R", minimized=TRUE) all_pointers <- sapply(all_pointers, deparse) to_find <- deparse(getWindowsHandle(dev)) if (to_find=="NULL") { warning("Device not found") NULL } else { names(all_pointers)[to_find==all_pointers] } } 

Now a few tests:

 > getTitle() Warning in getTitle() : Device not found NULL > windows(title="Test window one") > getTitle() [1] "Test window one (ACTIVE)" > getTitle(3) Warning in getTitle(3) : Device not found NULL > windows(title="Test window two") > windows(title="Test window three") > sapply(dev.list(), getTitle) windows windows windows "Test window one (inactive)" "Test window two (inactive)" "Test window three (ACTIVE)" 
+2
source

You could do this, but this approach would become cumbersome when working with multiple charts. I suspect that Richie is more interested in how / where R stores the name information as soon as you send it to the graphics device - like me.

0
source

All Articles