0

I am getting this error everytime I run library(matlib): Error: package or namespace load failed for ‘matlib’: .onLoad failed in loadNamespace() for 'rgl', details: call: rgl.init(initValue, onlyNULL) error: OpenGL is not available in this build

library(matlib)
Registered S3 methods overwritten by 'rgl':
  method               from
  knit_print.rglId         
  knit_print.rglOpen3d     
  sew.rglRecordedplot      
Error in dyn.load(dynlib <- getDynlib(dir)) : 
  unable to load shared object '/Users/nupur/Library/R/x86_64/4.1/library/rgl/libs/rgl.so':
  dlopen(/Users/nupur/Library/R/x86_64/4.1/library/rgl/libs/rgl.so, 6): Library not loaded: /opt/X11/lib/libGLU.1.dylib
  Referenced from: /Users/nupur/Library/R/x86_64/4.1/library/rgl/libs/rgl.so
  Reason: image not found
Warning:    Loading rgl's DLL failed. 
    This build of rgl depends on XQuartz, which failed to load.
 See the discussion in https://stackoverflow.com/a/66127391/2554330
Warning: Trying without OpenGL...
Error: package or namespace load failed for ‘matlib’:
 .onLoad failed in loadNamespace() for 'rgl', details:
  call: rgl.init(initValue, onlyNULL)
  error: OpenGL is not available in this build
Phil
  • 7,287
  • 3
  • 36
  • 66
  • What OS and R version are you using? How did you install R? Did you read the discussion mentioned in the error message? https://stackoverflow.com/a/66127391/2554330 – MrFlick Sep 13 '21 at 05:34
  • Have you installed [XQuartz](https://www.xquartz.org/)? – Roland Sep 13 '21 at 06:19
  • 1
    If you run `Sys.setenv(RGL_USE_NULL=TRUE)` before calling `library(matlib)`, you'll probably get past this error. Graphs using the `rgl` package won't display in R, but you can get them to display in a browser: see `?rgl::rglwidget`. – user2554330 Sep 13 '21 at 09:20

1 Answers1

2

Running this before library(matlib) worked for me:

Sys.setenv(RGL_USE_NULL=TRUE)
Andronicus
  • 25,419
  • 17
  • 47
  • 88