Skip to content
Back to formatted view

Raw Message

Message-ID: <7F081E1D-3562-4B03-A38A-E9A5F3DA00EE@uni-bonn.de>
Date: 2013-07-13T11:33:30Z
From: Simon Zehnder
Subject: Set window title for plot on any OS

Dear R-Users,

I am writing a package using S4 classes. In the generic method "plot" I want to set the title for the plotting window as I will have several windows and window titles help the users to distinguish the graphics without putting a title into the plot itself (this can be done by users whenever they want) 

So I created a helper function .setDeviceTitle which I called after the plot has been done:

".setDeviceTitle" <- function(title = "title", dev = dev.cur()) {
	dev <- names(dev)[1]
	
	## check for OS ##
	if (dev == "windows") {
		windows(title = title)
	} else if (dev == "X11") {
		X11(title = title)
	} else {
		quartz(title = title)
	}
}

The result is a new device with the title in addition to the old. Is it possible to give a window a title after the plot has been done? If not: Before I plot the device I cannot know what device it will be, so I thought about a check via capabilities():

if (any(names(capabilities()) == "X11")) {
	X11(title = title)
}
else if (any(names(capabilities)) == "windows") {
	windows(title = title)
} else {
	quartz(title = title)
}

I want to have a safe method, which works on each OS R can run. How would you solve the problem? 


Best 

Simon