How to build rgl in RStudio on a Mac?

When I build rgl in RStudio on my M3 Mac, it always fails to find X11, so it ends up being built without OpenGL support. This only happens in RStudio; builds in the terminal work.

To see the issue, you need to set up an ARM64 Mac for building and installing packages. Then check out https://github.com/dmurdoch/rgl as a project in RStudio, and click on Build | Clean and Install. What should happen if the tools are properly installed is that it will compile all the C++ files and build two *.so files: src/rgl.so, and inst/useNULL/rgl.so.

However, if the configure script can’t detect X11 and OpenGL support libs, it will only build one. After that running

library(rgl)

will result in a message “This build of rgl does not include OpenGL functions…”, followed by instructions on how to use WebGL.

How can I fix this?

First, as on any platform, you need to install several libraries to support rgl. See the README for a discussion of this.

What is special on MacOS on a system using any of the ARM64 chips (currently M1, M2 or M3) is that you need to link to libraries that support that architecture. CRAN has made those libraries and tools available; see https://mac.r-project.org/tools/ for downloads. They recommend that you install these tools in /opt/R/arm64.

If you do that, you should also put /opt/R/arm64/bin in first place on your search path, because some of the executables in that directory help rgl to configure itself for your system. For Intel Macs and other Unix-alikes, the tools would typically be put into /usr/local, and you may still have some of those in place if you have upgraded from another machine.

Unfortunately, the current RStudio version 2024.04.2+764 automatically puts /usr/local/bin at the head of the search path whenever R starts. This can cause rgl builds to fail.

There are several possible solutions:

  1. Don’t use RStudio to install rgl. You can install it by downloading the tarball and then from the terminal running

    R CMD INSTALL rgl_x.y.z.tar.gz
    

    where x.y.z is the version number you are installing. As long as you have your PATH environment variable set up properly, that should work.

  2. Within RStudio, you can change the PATH by getting the old one, then setting a new one. For example,

    Sys.setenv(PATH=paste0("/opt/R/arm64/bin:", Sys.getenv("PATH")))
    

    This adds a possibly duplicate copy of the proper directory at the start, and should allow you to build rgl from source and install it. The problem with this approach is that it has to be done every time before installing rgl, because this version of RStudio will mess up the PATH again after the install.

  3. I don’t recommend this one, but it’s possible: find every executable file that is in both /usr/local/bin and /opt/R/arm64/bin, and delete the copies in /usr/local/bin. If you do this, it won’t matter which order those two directories are listed in the PATH, it will still work. However, this is error-prone, and you might end up deleting something that shouldn’t be deleted. If you do it properly, then you should be able to build in RStudio without worrying about what it did to your PATH.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật