user2205916
user2205916

Reputation: 3456

X11 is not available in R

Problem

I'm following along some code and get an error related to X11. To recreate my error, I ran x11() and got the following:

> x11()
Error in x11() : X11 is not available

I have definitely plotted things in R that loaded the XQuartz program to display.

What I tried

Google researching

I Googled using my error message and searched through the first two pages of my results but didn't find any solutions that worked. Based on my perusal of solutions, I provided my system information above since it seems to be relevant somehow. Any ideas/solutions/new leads would be appreciated.

Upvotes: 16

Views: 32629

Answers (5)

Mehrad
Mehrad

Reputation: 3829

If you are compiling R in R 4.2.2 I realized that compiling normally would not build it with x11 capability. You have to specify it during ./configure by adding --with-x=yes.

Upvotes: 0

WestCoastProjects
WestCoastProjects

Reputation: 63042

You will need to download the R from cran (not Homebrew). After so doing the X11 will show up in capabilities() :

enter image description here

Upvotes: 1

Anthony O.
Anthony O.

Reputation: 24307

You have to have a local X server, so get XQuartz because you are on MacOS.

If you were on Ubuntu you could install the virtual framebuffer X11 server like said here:

apt-get install xvfb xauth xfonts-base

Now that you have X virtual framebuffer installed, you can start a new instance like said here:

Xvfb :0 -ac -screen 0 1960x2000x24 &

Then if your R is compiled with with-x configuration option (enabled by default), you should have X11 capability, and you just have to declare this in R:

Sys.setenv("DISPLAY"=":0")

Upvotes: 1

Tim Siwula
Tim Siwula

Reputation: 983

I had this same issue and installing R separately from Rstudio fixed it. You can download it from here and verify x11 is working using x11()

Upvotes: 1

IRTFM
IRTFM

Reputation: 263331

The XQuartz package is the Mac X11 and your version is the current one. I'm wondering if you need to reboot after installation although I don't claim to know that. (And it might not hurt to repair permissions.) On my Mac (running 3.3.0 on El Cap) I need to set width and height (in inches, not pixels or points);

 x11( width=3, height=3)

What do you get with:

Sys.getenv("DISPLAY")

Might be something along the lines of:

"/private/tmp/com.apple.launchd.KImNTikz8K/org.macosforge.xquartz:0"

Also run:

capabilities()

Upvotes: 4

Related Questions