如何检索绘图设备窗口的标题?

时间:2011-07-06 13:09:34

标签: r plot

您可以使用

设置绘图设备窗口的标题
windows(title = "The title")
#or equivalently
x11(title = "The title")

如何从绘图设备窗口中检索标题?

names(dev.cur())attributes(dev.cur())str(dev.cur())unclass(dev.cur())没有透露任何有用信息。

2 个答案:

答案 0 :(得分:2)

设备属性不应该导致它的窗口属性。

在Windows下,您可以尝试使用names(getWindowsHandles())来解决问题:

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

E.g。对于有效设备grep("\\(ACTIVE\\)$", names(getWindowsHandles()), value=TRUE),请返回标题。


比我想象的容易:

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]
    }
}

现在进行一些测试:

> 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)" 

答案 1 :(得分:0)


你可以这样做,但在处理多个情节时,这种方法会变得很麻烦。我怀疑Richie对于将标题信息发送到图形设备后如何/在何处存储标题信息更感兴趣 - 就像我一样。