6

I am trying to get R to do some very basic plotting and such in UNIX, but am getting a weirdo error relating to X11, when as far as I can tell I'm not even needing X11.

I have a matrix name d and want to save an image of a heatmap of this matrix without ever actually displaying the image (since I don't want to use X11). Here is my code:

png(file="my_image.png")
heatmap(d)
dev.off()

The problem is I am getting the following error:

Error in X11(paste("png::", filename, sep = ""), g$width, g$height, pointsize,  :
  unable to start device PNG

In addition: Warning message:

In png(file = "interative_hen.png") :
  unable to open connection to X11 display ''

I don't know this is happening, since I don't see how R is needing X11, and even if it does, X11 is installed and working properly for every application I tested it with.

Breakthrough
  • 34,847
jake9115
  • 1,249

1 Answers1

5

First, check to see if the version of R you're using has PNG capabilities. You can do this by calling the capabilities() function from an R prompt. It should print out a list similar to:

> capabilities()

jpeg    png    tiff    tcltk  X11    aqua     http/ftp  sockets
FALSE   FALSE  FALSE   TRUE   FALSE  FALSE    TRUE      TRUE

libxml  fifo   cledit  iconv  NLS    profmem  cairo
TRUE    TRUE   TRUE    TRUE   TRUE   FALSE    FALSE 

If you see FALSE under png, then you need to manually recompile R with explicit PNG support. So long as you have installed the necessary build dependencies, the build process should automatically enable PNG capabilities.


Lastly, assuming there's no local X server running on the cluster, your SSH client might not be properly configured - specifically, ensure that you have enabled X11 forwarding (using the -X or -Y flags if you are using a UNIX-like ssh tool). Alternatively, you can try using a virtual framebuffer.

See this Stack Overflow question for details: How to run R on a server without X11, and avoid broken dependencies.

Breakthrough
  • 34,847