[Rd] capabilities("X11"): Force refresh from within R? (... and minor documentation issue)

Henrik Bengtsson henrik.bengtsson at ucsf.edu
Wed May 6 22:37:26 CEST 2015

Is there a way to refresh capabilities("X11") without restarting R
such that it reflects the enabling/disabling of X11?


If I launch R with X11 server disabled (e.g. ssh -X / ssh -Y to remote
Linux but forgot to enable Xming on local Windows), then I get:

> capabilities("X11")

> x11()
Error in .External2(C_X11, d$display, d$width, d$height, d$pointsize,  :
  unable to start device X11cairo
In addition: Warning message:
In x11() : unable to open connection to X11 display ''

So far so good.  However, if I then enable the X11 server (e.g. start
Xming on Windows), I still get:

> capabilities("X11")


> x11()

successfully opens an X11 plot window.  In other words, the value of
capabilities("X11") is not reflecting the availability of X11; from

     X11: Are the 'X11' graphics device and the X11-based data editor
          available?  This loads the X11 module if not already loaded,
          and checks that the default display can be contacted unless a
          'X11' device has already been used.

Not sure what that last "...unless a 'X11' device has already been
used" actually means here; is it a disclaimer for the above behavior?

If I restart R, the I get:

> capabilities("X11")

I came up with the following approach that launches another R session
querying the availability of X11:

capabilitiesX11 <- function() {
  bin <- file.path(R.home("bin"), "Rscript")
  cmd <- "cat(capabilities('X11'))"
  value <- system2(bin, args=c("-e", dQuote(cmd)), stdout=TRUE)

> capabilitiesX11()
[1] TRUE

but it's certainly feels like a hack.

Is there a way to force a refresh of capabilities("X11") without restarting R?

BTW, the description of ?capabilities says: "Report on the optional
features which have been compiled into this build of R."  The
"compiled into this build" part seems too specific; the above shows
that capabilities() also reflects run-time availabilities.  Other
"properties" does this as well.



More information about the R-devel mailing list