Không thể thực hiện được các thuộc tính thiết bị gây ra thuộc tính cửa sổ.
Dưới cửa sổ bạn có thể thử gây rối với names(getWindowsHandles())
mà mang lại cho tôi:
> names(getWindowsHandles())
[1] "R Console"
[2] "The title (ACTIVE)"
[3] "R Information"
Ví dụ: cho thiết bị đang hoạt động grep("\\(ACTIVE\\)$", names(getWindowsHandles()), value=TRUE)
trả về tiêu đề.
Đó là dễ dàng hơn tôi nghĩ:
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]
}
}
Bây giờ một số xét nghiệm:
> 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)"
Tôi không cố gắng để được thông minh hoặc bất cứ điều gì, nhưng không thể bạn chỉ 'plotname = "Tiêu đề"; ' ' windows (title = plotname); ' ' plotname' – Seth