On 04/29/2010 02:21 AM, Dennis Fisher wrote:
Colleagues
I have a lengthy script that calls mtext. Under most circumstances, a graphics
device is open and a plot exists, in which case mtext works as expected.
However, there are some instances where the graphics device is open but no plot
exists. When mtext is called, I receive an error message:
Error in mtext(1) : plot.new has not been called yet
The solution is to confirm that:
a. the device is open: length(dev.list())> 0
b. whether plot.new has been called.
I need help on the latter - how does one test whether plot.new has been called?
Hi Dennis,
I use:
if(dev.cur() == 1) # there is no graphics device open
which always seems to be the null device. Since I have never had
occasion to switch to the null device, this is a sort of test for
whether there is another graphics device open, and thus whether plot.new
has been called (on the current device). While it has always worked for
me, I am aware that it is a Sneaky Trick and may not work in some
situations.
Jim
______________________________________________
R-help@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.