Error: package or namespace load failed for ‘rjags’

Error: package or namespace load failed for ‘rjags’

我有一台 M1 Macbook Pro 运行ning OS Big Sur,刚刚尝试安装 rjagsJAGS。我从 https://sourceforge.net/projects/mcmc-jags/ 下载 JAGS 没有问题,运行 install_packages("rjags"),但是当我 运行 library(rjags) 我得到这个错误:

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

我理解这意味着 R 无法“找到”JAGS 的安装。我正在为这个项目使用 renv,但即使我停用它并重新 运行 install_packages("rjags")library(rjags) 我也会收到错误消息(只是文件路径不同):

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

我是一名统计人员,没有太多后端计算机专业知识,所以非常感谢帮助解决这个问题!

请参阅 here 了解类似的 post。

那么你的苹果电脑上是否安装了正确版本的JAGS?

本质上,rjags 是一个 R 接口,它需要安装 JAGS(您提到的后端)才能运行。

按照说明 here 在配备 M1 芯片的 Apple 电脑上安装 JAGS。

同样来自上面的 link(来自 JAGS 开发团队):

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: 如果可以我会发表评论,但我是新来的,积分不够。