- Install jags: in the terminal using homebrew
brew install jags
- Install rjags: in R
install.packages("rjags")
library(rjags)
If you run into a problem like:
configure: error: C++ compiler cannot create executables
It's probably because R is not finding the right compiler, therefore you need to create or modify the file ~/.R/Makevars
Setting the correct CC and CXX, in my case:
CC=clang
CXX=clang++
Do this and then retry install.packages("rjags")
or devtools::install_url
.
I installed jags
via homebrew. However, my homebrew is setup on my home directory (/Users/casallas/homebrew
) rather than the default, /usr/local
.
When I do
install.packages("rjags")
everything works fine, except that loading the library doesn't work:
library(rjags)
Error : .onLoad failed in loadNamespace() for 'rjags', details:
call: dyn.load(file, DLLpath = DLLpath, ...)
error: unable to load shared object '/Users/casallas/Library/R/3.0/library/rjags/libs/rjags.so':
dlopen(/Users/casallas/Library/R/3.0/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.3.dylib
Referenced from: /Users/casallas/Library/R/3.0/library/rjags/libs/rjags.so
Reason: image not found
Error: package or namespace load failed for ‘rjags’
As you can see, rjags
is expecting jags to be in /usr/local
.
The easiest solution is to install rjags
from source, using devtools::install_url
with the following configure.args
, as specified in rjags README:
devtools::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'
"
)
Update: Using the terminal I made a Makevars file in the ~/.R folder containing the text
CC=clang
CXX=clang++
And tried again to install rjags but received the same error:
xcrun: error: unable to load libxcrun (dlopen(/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib, 0x0005): could not use '/Library/Developer/CommandLineTools/usr/lib/libxcrun.dylib' because it is not a compatible arch). this error message is repeated several times
checking for pkg-config... no
configure: Attempting legacy configuration of rjags
checking for jags... /usr/local/bin/jags
checking for g++... g++
checking whether the C++ compiler works... no
configure: error: in
/private/var/folders/sv/3zwcb1kj0s32rv6ky634dxx40000gn/T/Rtmp2YJdvZ/R.INSTALL235545c4ce2f/rjags': configure: error: C++ compiler cannot create executables See
config.log' for more detailsERROR: configuration failed for package ‘rjags’