Installing rjags in R on OSX Mavericks

2019-07-24 16:01发布

问题:

I am trying to install the package "rjags" in R but am running into the following error:

Loading required package: rjags

Error : .onLoad failed in loadNamespace() for 'rjags', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object '/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so':
  dlopen(/Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so, 10): Symbol not found: __ZN5RangeC1ERKSt6vectorIiSaIiEES4_
  Referenced from: /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so
  Expected in: /usr/local/lib/libjags.3.dylib
in /Library/Frameworks/R.framework/Versions/3.1/Resources/library/rjags/libs/rjags.so
Error: package ‘rjags’ could not be loaded

I've installed JAGS on my Mac (running Mavericks), and I am running R-3.1.2. I've tried installing from the url using the devtools package, as recommended by this site:

install_url("http://sourceforge.net/projects/mcmc-jags/files/rjags/3/rjags_3-2.tar.gz",
                      args="--configure-args='--with-jags-include=/Users/casallas/homebrew/opt/jags/include/JAGS        
                                              --with-jags-lib=/Users/casallas/homebrew/opt/jags/lib'
                            "
                      )

I've also gone through the instructions on this other site , trying the different versions of JAGS and receive the same error. I'm at a loss for what to try next and am sure the solution is simple. Does anyone have any insights? Thanks so much!

回答1:

I found that while I was unable to install rjags from the url, if I installed the package from source on my computer I was successful. I did this by downloading the appropriate package from here (which for me was rjags_3-14.tgz) and ran the following command:

install.packages(path_to_file, repos = NULL, type="source")


回答2:

The error:

    Symbol not found: __ZN5RangeC1ERKSt6vectorIiSaIiEES4_

Is (nearly) always caused by a mismatch between standard libraries between the Mavericks build of R (actually rjags) and Snow Leopard build of JAGS (or vice versa). For more info see the instructions at https://sourceforge.net/projects/mcmc-jags/files/JAGS/3.x/Mac%20OS%20X/

I'm guessing that compiling the package yourself from source worked because it matched the version of the standard library that JAGS is using, but this will no longer match the version that R is using (although I'm not sure if this is a major problem, it is not recommended). You would be better to match the builds of R and JAGS and use the pre-built rjags library from CRAN.

It is interesting that you say you have tried both builds of JAGS but I suggest trying again along these lines:

1) Use .Platform$pkgType in R to confirm if it you are using mac.binary (SL) or mac.binary.mavericks (Mavericks) - or failing that re-install the Mavericks binary of R from CRAN

2) Exit R

3) Re-install the appropriate version of JAGS

4) Re-open R and re-install the rjags library from CRAN

5) Try library(rjags)

If this doesn't work can you provide more information so I can try and track down a possible problem with the JAGS builds?

Thanks,

Matt



标签: r jags