From simon.urbanek at r-project.org  Fri Apr 25 03:22:40 2014
From: simon.urbanek at r-project.org (Simon Urbanek)
Date: Thu, 24 Apr 2014 21:22:40 -0400
Subject: [Rd] palette() can hang and fail due to X11
In-Reply-To: <20140424201308.GA22592@piskorski.com>
References: <20140424201308.GA22592@piskorski.com>
Message-ID: <9D39ED59-7E29-4C11-B99D-2A0FDD85B8D5@r-project.org>

Andrew,

palette is a property recorded in the graphics device* and therefore R will create a new device (see dev.new()) if only the null device is open. Which device is really up to your settings, so you could adjust your preferred device depending on what you want it to be.

The bottom line is that you probably don't want to set the palette if you don't have a device that could be used. The delay you see is probably due to your local settings that seem to choose X11 as the default device which may or may not work depending on the different way you start R and/or the availability of the server you DISPLAY is pointing to.

* - this has changed in R 3.0.0, quote:

 Palette changes get recorded on the display list, so
 replaying plots (including when resizing screen devices and using
 dev.copy()) will work better when the palette is changed
 during a plot.

Cheers,
Simon


On Apr 24, 2014, at 4:13 PM, Andrew Piskorski <atp at piskorski.com> wrote:

> For many years, when my R process starts up I've been automatically
> setting my preferred default plot colors, basically like so:
> 
>  my.colors <-
>     c("black" ,"red" ,"gold" ,"sky blue" ,"green" ,"blue" ,"orange"
>       ,"grey" ,"hot pink" ,"brown" ,"sea green" ,"cyan" ,"purple" ,"tomato1")
>  require("grDevices")
>  palette(my.colors)
> 
> That seemed to work reliably in all 2.x versions of R, regardless of
> whether my R was interactive or not, or if my Linux, ssh, and screen
> environment had X-Windows properly set up or not.  It Just Worked.
> 
> However, now in R 3.1.0 Patched (2014-04-15 r65398, on Linux),
> depending on whether I have a good X-Windows connection or not it can
> fail like so:
> 
>  Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  :  
>    unable to start device X11 
> 
> Simply wrapping the palette() call in try() of course helps keep that
> error from breaking the rest of my R start up.  However, occasionally
> the call to palette() will hang for perhaps a minute, unexpectedly
> locking up my R process until it finishes whatever it was doing.
> 
> But, all I want to do here is set my default colors to the length 14
> vector above, which seems like something that SHOULD be simple...  Is
> there some way for me to reliably do that WITHOUT invoking all this
> extra X11 device machinery?
> 
> The relevant C code appears to be "palette" in
> "src/library/grDevices/src/colors.c" and "do_dotcallgr" for
> .Call.graphics in "src/main/dotcode.c", but I don't understand what
> part is triggering the additional complex behavior, nor how I should
> avoid it.
> 
> Any advice on how I should handle this robustly?  (Thanks!)
> 
> -- 
> Andrew Piskorski <atp at piskorski.com>
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 



[Rd] palette() can hang and fail due to X11
Simon Urbanek