Error: package or namespace load failed for ‘rjags’ - r

I have a M1 Macbook Pro running OS Big Sur and just tried to install rjags and JAGS. I downloaded JAGS from https://sourceforge.net/projects/mcmc-jags/ without a problem, and ran install_packages("rjags"), but when I run library(rjags) I get this error:
Loading required package: coda
Error: package or namespace load failed for ‘rjags’:
.onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Users/afredston/Library/Caches/org.R-project.R/R/renv/cache/v5/R-4.1/aarch64-apple-darwin20/rjags/4-12/e8a71b3a154c8e68c152b4cfbebfdd97/rjags/libs/rjags.so':
dlopen(/Users/afredston/Library/Caches/org.R-project.R/R/renv/cache/v5/R-4.1/aarch64-apple-darwin20/rjags/4-12/e8a71b3a154c8e68c152b4cfbebfdd97/rjags/libs/rjags.so, 10): Library not loaded: /opt/R/arm64/lib/libjags.4.dylib
Referenced from: /Users/afredston/Library/Caches/org.R-project.R/R/renv/cache/v5/R-4.1/aarch64-apple-darwin20/rjags/4-12/e8a71b3a154c8e68c152b4cfbebfdd97/rjags/libs/rjags.so
Reason: image not found
I understand this means that R cannot "find" the installation of JAGS. I am using renv for this project, but even if I deactivate it and re-run install_packages("rjags") and library(rjags) I get the error (just with different file paths):
Loading required package: coda
Error: package or namespace load failed for ‘rjags’:
.onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rjags/libs/rjags.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /opt/R/arm64/lib/libjags.4.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rjags/libs/rjags.so
Reason: image not found
I'm a stats person without much back-end computer expertise so I'd appreciate help resolving this!

See here for a similar post.
So have you installed the correct version of JAGS on your Apple computer?
Essentially, rjags is an R interface and it needs an installed JAGS (a back-end you mentioned) to function.
Follow the instructions here to install JAGS on Apple computers with M1 chips.
Also from the link above (from JAGS development team):
A readme file is provided in the disk image - please do read it.
If you find that rjags fails to load after installation of JAGS,
make sure you have installed the Mavericks or El Capitan binary of
R from CRAN. If you really need the Snow Leopard build of R (or if
you compiled R yourself) you will have to compile JAGS from source.
If you have followed the instructions above (and in the relevant
README file) and are still having problems with installation of
these binaries, please let us know via the JAGS discussion forum.
PS: I would comment if I could, but I am new here and don't have enough points to do so.

Related

How to install the rgl package in macOS Big Sur

I have been trying to install the rgl package in my macOS Big Sur, but I have failed each time.
I have downloaded R from the CRAN website, and have also installed Xquartz. After rebooting the computer, I tried to install the rgl package from the R console. It installs successfully, but whenever I type library("rgl") in the R console, the package does not load, and instead, this is shown :
Error in dyn.load(dynlib <- getDynlib(dir)) :
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so, 6): Symbol not found: _hb_buffer_add_utf8
Referenced from: /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so
Expected in: flat namespace
in /Library/Frameworks/R.framework/Versions/4.1-arm64/Resources/library/rgl/libs/rgl.so
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 headed to the link that this error message mentions, and tried uninstalling rgl and Xquartz, and reinstalling them again, but the issue remains.
Moreover, here it is said that I am supposed to delete org.xquartz.startx.plist from /Library/LaunchDaemons, but from the terminal, after navigating to the Library directory, it seems that there is nothing named LaunchDaemons or LaunchAgents.
Any help would be appreciated. I am using macOS Big Sur 11.4, Xquartz 2.8.1 and rgl 0.106.8. Thanks.

Cannot load R package gmm on newest macbook with Apple M1 chip

I'm trying to load package gmm (running "library(gmm)") and get this error message below.
It seems unfixable, as it states that my gfortran/lib/libgomp.1.dylib has the wrong architecture? I'm guessing this is related to the new Mac architecture?
library(gmm)
Loading required package: sandwich
Error: package or namespace load failed for ‘gmm’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so':
dlopen(/Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so, 6): Library not loaded: /usr/local/gfortran/lib/libgomp.1.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/4.0/Resources/library/gmm/libs/gmm.so
Reason: no suitable image found. Did find:
**/usr/local/gfortran/lib/libgomp.1.dylib: mach-o, but wrong architecture**
/usr/local/gfortran/lib/libgomp.1.dylib: mach-o, but wrong architecture
I had the same issue on R version 4.1. Found a similar question here which points to installing (or updating) your gfortran installation here. Once I did that and restarted R, the gmm package was able to find the missing image(s) automatically when I loaded the package.

Symbolic Matrix Computation in R

I need to do symbolic computation with matrices in R, preferably using the rSymPy package. I am running everything on Mac OS. There is a problem with loading the rJava package, however. I get the following error:
Error: package or namespace load failed for ‘rJava’: .onLoad failed in loadNamespace() for 'rJava', details: call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so': dlopen(/Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so, 6): Library not loaded: /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home/lib/server/libjvm.dylib Referenced from: /Library/Frameworks/R.framework/Versions/3.5/Resources/library/rJava/libs/rJava.so Reason: image not found
I have read through Problems when trying to load a package in R due to rJava and Unable to load rJava on R, as well as other similar questions. This is very frustrating - any help would be appreciated!
My end goal here is to perform matrix reduction and manipulation in R with variables (i.e. symbolic matrix computations). If there are any other suggestions on how to do this in R, please let me know.
First thing to try is to run the following from a terminal:
R CMD javareconf

I am facing issues while trying to install emojifont package on Mac book

I am installing emojifont package. The package installs properly however when I try to call it through the library function I get the following error
Error: package or namespace load failed for ‘emojifont’:
.onLoad failed in loadNamespace() for 'sysfonts', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so, 6): Library not loaded: /opt/X11/lib/libfreetype.6.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.6/Resources/library/sysfonts/libs/sysfonts.so
Reason: image not found
What ended up working for me was installing XQuartz. I had this problem with both emojifont and sysfonts until I installed XQuartz and then both loaded without problems. I can't tell you much about what XQuartz is doing but it seems to be needed for the compatibility between MacOS and these packages.
Other people with this problem seemed to be having issues with their sysfonts install (like it needed to be updated, etc.) but that didn't work for me, instead I got an error when using trying to load both the sysfonts and the emojifont package. If you look at this line in the error "Library not loaded: /opt/X11/lib/libfreetype.6.dylib", that seems to be missing in the error message of people with only the sysfonts problem.
Hope this saves someone the 2 hours I just spent searching!

R error loading package rJava and openNLP

I get this error message while trying to load the rJava or the openNLP packages through the function library(openNLP) or library(rJava):
Error: package or namespace load failed for ‘rJava’:
.onLoad in loadNamespace() for 'rJava' failed, details:
call: dirname(this$RuntimeLib)
error: a character vector argument expected
I have no problems loading other packages, e.g. NLP.
Does somebody know what the problem is?
I have updated the Java SE Development Kit and now I get no error message anymore. So this seems to be the solution for the problem.
I solved this problem by installing Java SE Development Kit 8.
Link for Download: http://www.oracle.com/technetwork/pt/java/javase/downloads/jdk8-downloads-2133151.html

Resources