Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Installing rjags on a Mac

To install

  1. Install jags: in the terminal using homebrew brew install jags
  2. Install rjags: in R
install.packages("rjags")
library(rjags)

Potential issues

Compiler issues

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.

Non-default jags installation

The problem

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 solution

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'
                            "
                      )
@vmivm

This comment has been minimized.

Show comment
Hide comment
@vmivm

vmivm Feb 13, 2016

Hi!
thank you for your writing. that is really helpful.
but i still have trouble to load rjags, i think it is installed via homebrew successfully. so now i can see it(rjags) in the package section in the right below part of Rstudio.

BUT, I have no idea why i can't load rjags.
here is the error message, When i do 'library(rjags)'


Error in get(method, envir = home) :
lazy-load database '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rjags/R/rjags.rdb' is corrupt


can you give me a hand plz?

Many thanks. :)

vmivm commented Feb 13, 2016

Hi!
thank you for your writing. that is really helpful.
but i still have trouble to load rjags, i think it is installed via homebrew successfully. so now i can see it(rjags) in the package section in the right below part of Rstudio.

BUT, I have no idea why i can't load rjags.
here is the error message, When i do 'library(rjags)'


Error in get(method, envir = home) :
lazy-load database '/Library/Frameworks/R.framework/Versions/3.2/Resources/library/rjags/R/rjags.rdb' is corrupt


can you give me a hand plz?

Many thanks. :)

@Ibrocas

This comment has been minimized.

Show comment
Hide comment
@Ibrocas

Ibrocas Feb 20, 2016

Good evening,

I installed jags from source as you suggested in the solution above but I get the following error:

Downloading package from url: http://sourceforge.net/projects/mcmc-jags/files/rjags/3/rjags_3-2.tar.gz
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
Error in if (!file.exists(file.path(pkg_path, "DESCRIPTION"))) { :
argument is of length zero
In addition: Warning messages:
1: In utils::untar(src, exdir = target, compressed = "gzip") :
‘/usr/bin/tar -xf '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/file16e2866ff43.tar.gz' -C '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/devtools16e761dfac8'’ returned error code 1
2: running command '/usr/bin/tar -tf '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/file16e2866ff43.tar.gz'' had status 1
3: In min(slashes) : no non-missing arguments to min; returning Inf

I have been following all instructions. Thanks for giving me any suggestion :)

Ibrocas commented Feb 20, 2016

Good evening,

I installed jags from source as you suggested in the solution above but I get the following error:

Downloading package from url: http://sourceforge.net/projects/mcmc-jags/files/rjags/3/rjags_3-2.tar.gz
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
tar: Unrecognized archive format
tar: Error exit delayed from previous errors.
Error in if (!file.exists(file.path(pkg_path, "DESCRIPTION"))) { :
argument is of length zero
In addition: Warning messages:
1: In utils::untar(src, exdir = target, compressed = "gzip") :
‘/usr/bin/tar -xf '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/file16e2866ff43.tar.gz' -C '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/devtools16e761dfac8'’ returned error code 1
2: running command '/usr/bin/tar -tf '/var/folders/0b/xd0wy5jx0t1cd2tys9nktzyc0000gn/T//RtmpXIK3gv/file16e2866ff43.tar.gz'' had status 1
3: In min(slashes) : no non-missing arguments to min; returning Inf

I have been following all instructions. Thanks for giving me any suggestion :)

@Ibrocas

This comment has been minimized.

Show comment
Hide comment
@Ibrocas

Ibrocas Feb 20, 2016

Problem solved: the solution involves looking for version 4 (none of the other versions worked for me) as displayed here:

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

Ibrocas commented Feb 20, 2016

Problem solved: the solution involves looking for version 4 (none of the other versions worked for me) as displayed here:

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

@edithelg

This comment has been minimized.

Show comment
Hide comment
@edithelg

edithelg Mar 2, 2017

Hi can you please help me with this??

Downloading GitHub repo rasmusab/bayesian_first_aid@master
from URL https://api.github.com/repos/rasmusab/bayesian_first_aid/zipball/master
Installing BayesianFirstAid
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ
--no-save --no-restore --quiet CMD INSTALL
'/private/var/folders/lj/0vlzq1w92r18dwbb2hkwygcm0000gn/T/RtmpC1O3eb/devtools109ad49ae6a91/rasmusab-bayesian_first_aid-d80c0fd'
--library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library'
--install-tests

  • installing source package ‘BayesianFirstAid’ ...
    ** R
    ** inst
    ** tests
    ** preparing package for lazy loading
    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.3/Resources/library/rjags/libs/rjags.so':
    dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.4.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags/libs/rjags.so
    Reason: image not found
    Error : package ‘rjags’ could not be loaded
    ERROR: lazy loading failed for package ‘BayesianFirstAid’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/BayesianFirstAid’
    Error: Command failed (1)

edithelg commented Mar 2, 2017

Hi can you please help me with this??

Downloading GitHub repo rasmusab/bayesian_first_aid@master
from URL https://api.github.com/repos/rasmusab/bayesian_first_aid/zipball/master
Installing BayesianFirstAid
'/Library/Frameworks/R.framework/Resources/bin/R' --no-site-file --no-environ
--no-save --no-restore --quiet CMD INSTALL
'/private/var/folders/lj/0vlzq1w92r18dwbb2hkwygcm0000gn/T/RtmpC1O3eb/devtools109ad49ae6a91/rasmusab-bayesian_first_aid-d80c0fd'
--library='/Library/Frameworks/R.framework/Versions/3.3/Resources/library'
--install-tests

  • installing source package ‘BayesianFirstAid’ ...
    ** R
    ** inst
    ** tests
    ** preparing package for lazy loading
    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.3/Resources/library/rjags/libs/rjags.so':
    dlopen(/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.4.dylib
    Referenced from: /Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags/libs/rjags.so
    Reason: image not found
    Error : package ‘rjags’ could not be loaded
    ERROR: lazy loading failed for package ‘BayesianFirstAid’
  • removing ‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/BayesianFirstAid’
    Error: Command failed (1)
@luceromz

This comment has been minimized.

Show comment
Hide comment
@luceromz

luceromz Oct 5, 2017

Hi!

Im having this problem working with Yosemite 10.10.5

configure: error: "automatic detection of JAGS failed. Please supply the prefix for JAGS with the --with-jags-prefix option. See the README file for details."
ERROR: configuration failed for package 'rjags'

  • removing '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags'
  • restoring previous '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags'
    Installation failed: Command failed (1)

luceromz commented Oct 5, 2017

Hi!

Im having this problem working with Yosemite 10.10.5

configure: error: "automatic detection of JAGS failed. Please supply the prefix for JAGS with the --with-jags-prefix option. See the README file for details."
ERROR: configuration failed for package 'rjags'

  • removing '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags'
  • restoring previous '/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rjags'
    Installation failed: Command failed (1)
@lorenzwalthert

This comment has been minimized.

Show comment
Hide comment
@lorenzwalthert

lorenzwalthert Jan 4, 2018

thanks so much @Ibrocas, your solution worked for me.

thanks so much @Ibrocas, your solution worked for me.

@teefryingpan

This comment has been minimized.

Show comment
Hide comment
@teefryingpan

teefryingpan Mar 6, 2018

@luceromz I am still having that problem as well. Any solutions?

@luceromz I am still having that problem as well. Any solutions?

@JNavelski

This comment has been minimized.

Show comment
Hide comment
@JNavelski

JNavelski Mar 25, 2018

@luceromz @teefryingpan

Operating system: MacOS 10.13.3
R Version: 3.4.4

I have installed rjags,using both the standard way of dowloading a package and through @Ibrocas comment, but for some reason I cannot get it to load the rjags package from my package library. There error code I am getting is:

library(rjags)
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/3.4/Resources/library/rjags/libs/rjags.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.4.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rjags/libs/rjags.so
Reason: image not found

Can anyone offer some advice on how to call rjags? I have removed and reinstalled multiple times.

Thanks to everyone on the forum!

JNavelski commented Mar 25, 2018

@luceromz @teefryingpan

Operating system: MacOS 10.13.3
R Version: 3.4.4

I have installed rjags,using both the standard way of dowloading a package and through @Ibrocas comment, but for some reason I cannot get it to load the rjags package from my package library. There error code I am getting is:

library(rjags)
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/3.4/Resources/library/rjags/libs/rjags.so':
dlopen(/Library/Frameworks/R.framework/Versions/3.4/Resources/library/rjags/libs/rjags.so, 10): Library not loaded: /usr/local/lib/libjags.4.dylib
Referenced from: /Library/Frameworks/R.framework/Versions/3.4/Resources/library/rjags/libs/rjags.so
Reason: image not found

Can anyone offer some advice on how to call rjags? I have removed and reinstalled multiple times.

Thanks to everyone on the forum!

@CommonClimate

This comment has been minimized.

Show comment
Hide comment
@CommonClimate

CommonClimate Jun 6, 2018

Just wanted to thank you for taking the time to write this. Everything appears to be working, thanks to your instructions.

Just wanted to thank you for taking the time to write this. Everything appears to be working, thanks to your instructions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment