Home > other >  Error: package or namespace load failed for ‘rjags’
Error: package or namespace load failed for ‘rjags’

Time:12-31

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!

CodePudding user response:

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