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
Set window title for plot on any OS
6 messages · Duncan Murdoch, Rolf Turner, Simon Zehnder +1 more
On 13-07-13 1:33 PM, Simon Zehnder wrote:
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?
Use dev.new() rather than picking a particular device. If all the
possible devices support the "title" argument, then
dev.new(title=title)
will be fine. If you might need more customization (or want to protect
against a user who chooses a device that doesn't have "title" as an
argument), use getOption("device") to examine the call that will be used.
Duncan Murdoch
Hi Duncan,
thank you very much for your advice! That makes it all work.
I check in addition for a "title" argument in the device via
if (any(names(getOption("device")) == TRUE)) {
dev.new(title = "title")
}
Thanks again!
Simon
On Jul 13, 2013, at 2:40 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 13-07-13 1:33 PM, Simon Zehnder wrote:
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?
Use dev.new() rather than picking a particular device. If all the possible devices support the "title" argument, then
dev.new(title=title)
will be fine. If you might need more customization (or want to protect against a user who chooses a device that doesn't have "title" as an argument), use getOption("device") to examine the call that will be used.
Duncan Murdoch
I think you ought to take a look at
fortune("Lewis Carroll")
cheers,
Rolf Turner
On 14/07/13 01:45, Simon Zehnder wrote:
Hi Duncan,
thank you very much for your advice! That makes it all work.
I check in addition for a "title" argument in the device via
if (any(names(getOption("device")) == TRUE)) {
dev.new(title = "title")
}
Thanks again!
Simon
On Jul 13, 2013, at 2:40 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 13-07-13 1:33 PM, Simon Zehnder wrote:
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?
Use dev.new() rather than picking a particular device. If all the possible devices support the "title" argument, then
dev.new(title=title)
will be fine. If you might need more customization (or want to protect against a user who chooses a device that doesn't have "title" as an argument), use getOption("device") to examine the call that will be used.
Duncan Murdoch
Haha, good point!
So, the correct code is:
any(names(formals(getOption("device"))) == "title") {
dev.new(title = "title")
}
Thanks for correcting my approach Rolf!
Best
Simon
On Jul 14, 2013, at 1:02 AM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
I think you ought to take a look at
fortune("Lewis Carroll")
cheers,
Rolf Turner
On 14/07/13 01:45, Simon Zehnder wrote:
Hi Duncan,
thank you very much for your advice! That makes it all work.
I check in addition for a "title" argument in the device via
if (any(names(getOption("device")) == TRUE)) {
dev.new(title = "title")
}
Thanks again!
Simon
On Jul 13, 2013, at 2:40 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
On 13-07-13 1:33 PM, Simon Zehnder wrote:
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?
Use dev.new() rather than picking a particular device. If all the possible devices support the "title" argument, then
dev.new(title=title)
will be fine. If you might need more customization (or want to protect against a user who chooses a device that doesn't have "title" as an argument), use getOption("device") to examine the call that will be used.
Duncan Murdoch
On Jul 14, 2013, at 3:42 AM, Simon Zehnder wrote:
Haha, good point!
So, the correct code is:
any(names(formals(getOption("device"))) == "title") {
dev.new(title = "title")
}
This might be easier to read:
"title" %in% names(formals(getOption("device")) )
David.
> Thanks for correcting my approach Rolf!
>
>
> Best
>
> Simon
>
> On Jul 14, 2013, at 1:02 AM, Rolf Turner <rolf.turner at xtra.co.nz> wrote:
>
>>
>>
>> I think you ought to take a look at
>>
>> fortune("Lewis Carroll")
>>
>> cheers,
>>
>> Rolf Turner
>>
>> On 14/07/13 01:45, Simon Zehnder wrote:
>>> Hi Duncan,
>>>
>>> thank you very much for your advice! That makes it all work.
>>>
>>> I check in addition for a "title" argument in the device via
>>>
>>> if (any(names(getOption("device")) == TRUE)) {
>>> dev.new(title = "title")
>>> }
>>>
>>> Thanks again!
>>>
>>> Simon
>>>
>>> On Jul 13, 2013, at 2:40 PM, Duncan Murdoch <murdoch.duncan at gmail.com> wrote:
>>>
>>>> On 13-07-13 1:33 PM, Simon Zehnder wrote:
>>>>> 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?
>>>> Use dev.new() rather than picking a particular device. If all the possible devices support the "title" argument, then
>>>>
>>>> dev.new(title=title)
>>>>
>>>> will be fine. If you might need more customization (or want to protect against a user who chooses a device that doesn't have "title" as an argument), use getOption("device") to examine the call that will be used.
>>>>
>>>> Duncan Murdoch
>>>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius
Alameda, CA, USA