Package rgl in R not loading in Mac OS

17.6k Views Asked by At

I installed the rgl package (0.104.16) in R (3.6.3), but it does not load. I don't get any errors. It just never ends loading. I tried reinstalling R and RStudio and also Xquartz. Nothing is working. I have Mac OS Catalina version 10.15.7. Any help would be highly appreciated! Cheers

2

There are 2 best solutions below

9
On

Edited to add new details and suggested fixes.

This appears to be due to problems in the 2.8.0beta version of Xquartz that was released in early February. There are two problems:

  • It makes incompatible changes to libX11.6.dylib, so programs (like the CRAN binaries of rgl) that were built for the 2.7.11 release will not work. If you build rgl (and everything else that uses X11) from source, it may be okay -- it was for me.

  • When you uninstall it, it leaves behind two programs that run at startup: /Library/LaunchDaemons/org.xquartz.startx.plist (runs when you reboot your system) and /Library/LaunchAgents/org.xquartz.startx.plist (runs when you login). If you then install 2.7.11, these will fail to run (probably because of the libX11 change mentioned above). At that point, nothing in X11 works.

So the solution appears to be:

  • Uninstall XQuartz by dragging it from the Applications/Utilities folder to the trash.
  • Uninstall rgl by running remove.packages("rgl") in R.
  • Delete those two files named org.xquartz.startx.plist from /Library/LaunchDaemons and /Library/LaunchAgents.
  • Reboot your system to remove the processes started from those files.
  • Reinstall XQuartz 2.7.11.
  • Reinstall rgl either from CRAN or from source.

If I'm wrong and that process doesn't work, this will almost certainly work as long as your rgl version is at least 0.105.12 (but won't give you any rgl windows):

# Start a new session
options(rgl.useNULL = TRUE)
library(rgl)

To see your displays, run the rglwidget() function, and they'll display in a browser or the RStudio viewer pane.

0
On

I installed XQuartz 2.8.5, restarted my M1 Mac, and i could install and run the rayshader demo. the problem apparently was that rgl had x386 libraries but not ARM ones (or at least aliases to them), but installing the latest XQuartz fixed that without having to fiddle with removing files