friendly / matlib

Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics
http://friendly.github.io/matlib/
65 stars 16 forks source link

plotEqn3d(A,b) does not plot on apple silicon but plotEqn(A,b) works fine!! #40

Closed fuxelius closed 1 year ago

fuxelius commented 3 years ago

Hi, I am testing your excellent package but run into a problem! 2D works just fine in Quartz but 3D shows nothing!

test code:

options(rgl.useNULL=TRUE) library(rgl) library(matlib)

A <- matrix(c(1, 2, 1, 3, 8, 7, 2, 7, 9), 3, 3) b <- c(4, 20, 23)

showEqn(A, b)

plotEqn3d(A,b) # Does not work! (Apple Silicon)

Solve(A, b)

john-d-fox commented 3 years ago

Dear H-H. Fuxelius,

Perhaps I'm confused about what you're trying to do, but doesn't setting options(rgl.useNULL=TRUE) turn off rgl graphics but still allow the rgl package to load?

From the help for the rgl package: "This function is checked by the initialization code when the rgl package is loaded. Thus if you want to run RGL on a system where there is no graphics support, you should run options(rgl.useNULL = TRUE) or set the environment variable RGL_USE_NULL=TRUE before calling library(rgl) (or other code that loads rgl), and it will not fail in its attempt at initialization."

I hope this helps, John

John Fox, Professor Emeritus McMaster University Hamilton, Ontario, Canada web: https://socialsciences.mcmaster.ca/jfox/

On 2021-08-19 7:38 a.m., H-H. Fuxelius wrote:

options(rgl.useNULL=TRUE) library(rgl) library(matlib)

A <- matrix(c(1, 2, 1, 3, 8, 7, 2, 7, 9), 3, 3) b <- c(4, 20, 23)

showEqn(A, b)

plotEqn3d(A,b) # Does not work! (Apple Silicon)

Solve(A, b)

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/friendly/matlib/issues/40, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLSAQSMHVLVCUPBEVP4K7DT5TUK5ANCNFSM5COBAPGQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email.

fuxelius commented 3 years ago

Dear John, thanks for your time and answer!

When I run 'library(rgl)' I got the following message:

    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 '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so':
      dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so, 6): Library not loaded: /opt/X11/lib/libGLU.1.dylib
      Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so
      Reason: image not found
    Error: package or namespace load failed for ‘rgl’:
     .onLoad failed in loadNamespace() for 'rgl', details:
      call: rgl.init(initValue, onlyNULL)
      error: OpenGL is not available in this build
    In addition: Warning messages:
    1:  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 
    2: Trying without OpenGL...

I applied the code from https://stackoverflow.com/a/66127391/2554330 and now I got it to work :)

Working code on an M1 apple silicon Mac (R-Studio)!

    options(rgl.useNULL=TRUE)
    library(rgl)
    library(matlib)

    A <- matrix(c(1, 2, 1, 3, 8, 7, 2, 7, 9), 3, 3)
    b <- c(4, 20, 23)

    showEqn(A, b)

    plotEqn3d(A,b)
    rglwidget()

    Solve(A, b)

Many thanks! Hans-Henrik Fuxelius

john-d-fox commented 3 years ago

Dear Hans-Henrik,

This really isn't the right place to ask questions about the rgl package, which we don't maintain.

You're encountering a known problem with rgl on the newest version of R under macOS, which has been discussed on the R-SIG-MAC email list; you can find and follow the thread at https://stat.ethz.ch/pipermail/r-sig-mac/2021-August/014149.html.

You'll see that Duncan Murdoch, the maintainer of rgl, has a solution that you should be able to install via

remotes::install_github("dmurdoch/rgl using configpatch")

if you're set up to build R packages on your mac. Otherwise, I imagine that the updated version of rgl will eventually find its way to CRAN.

Best, John

John Fox, Professor Emeritus McMaster University Hamilton, Ontario, Canada web: https://socialsciences.mcmaster.ca/jfox/

On 2021-08-20 3:58 a.m., H-H. Fuxelius wrote:

Dear John, thanks for your time and answer!

When I run 'library(rgl)' I got the following message:

|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 '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so': dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so, 6): Library not loaded: /opt/X11/lib/libGLU.1.dylib Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/rgl/libs/rgl.so Reason: image not found Error: package or namespace load failed for ‘rgl’: .onLoad failed in loadNamespace() for 'rgl', details: call: rgl.init(initValue, onlyNULL) error: OpenGL is not available in this build In addition: Warning messages: 1: 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 2: Trying without OpenGL... |

I applied the code from https://stackoverflow.com/a/66127391/2554330 https://stackoverflow.com/a/66127391/2554330 and now I got it to work :)

Working code on an M1 apple silicon Mac (R-Studio)!

|options(rgl.useNULL=TRUE) library(rgl) library(matlib) A <- matrix(c(1, 2, 1, 3, 8, 7, 2, 7, 9), 3, 3) b <- c(4, 20, 23) showEqn(A, b) plotEqn3d(A,b) rglwidget() Solve(A, b) |

Many thanks! Hans-Henrik Fuxelius

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/friendly/matlib/issues/40#issuecomment-902509222, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADLSAQVVPZKV6RZXC3SMW4LT5YDJBANCNFSM5COBAPGQ. Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&utm_campaign=notification-email.

fuxelius commented 3 years ago

Dear John,

Thanks a lot for your time, I will dwell further into rgl ;)

Best, Hans-Henrik