如何检索剧情设备窗口的标题?

7
您可以使用以下方法设置绘图设备窗口的标题:
windows(title = "The title")
#or equivalently
x11(title = "The title")

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

names(dev.cur())attributes(dev.cur())str(dev.cur())unclass(dev.cur()) 并没有显示任何有用的信息。


我不是要表现得很聪明或别的什么,但是你不能只是简单地把以下代码翻译成中文吗?plotname="The title"; windows(title = plotname); plotname - Seth
2个回答

2

由于它是窗口属性,因此不应该从设备属性中获取。

在 Windows 下,您可以尝试使用names(getWindowsHandles())来混淆,这会给我带来:

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

例如,对于活动设备,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)" 

太棒了!这正是我想要的。 - Richie Cotton

0

你可以这样做,但是当处理多个图时,这种方法会变得繁琐。我猜Richie更感兴趣的是当你将标题信息发送到图形设备后,R在哪里存储它。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接