2011-07-06 12 views
7

あなたはプロットデバイスウィンドウからタイトルを取得する方法プロットデバイスウィンドウのタイトルをどのように取得しますか?

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

でプロットデバイスウィンドウのタイトルを設定することができますか?

names(dev.cur()),attributes(dev.cur()),str(dev.cur())およびunclass(dev.cur())は何も有用であるとは明らかでない。

+0

私は=スマートか何かになろうとしますが、あなただけの 'plotnameを傾けるわけではありません"タイトル"; ' 'ウィンドウ(タイトル=プロット名); ' ' plotname' – Seth

答えて

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

ブラボー!これは私が欲しかったものです。 –

0

これは可能ですが、複数のプロットを扱う場合にはこのアプローチは煩雑になります。私はリッチーがグラフィックデバイスに送ると、Rがタイトル情報をどのようにして/どのように保存するかにもっと興味があると思っています。

関連する問題