Cannot install rjags Ubuntu 20.04

I recently decided I should learn a bit about Bayesian statistics so I bought a copy of John Kruschke”s *Doing Bayesian Data Analysis and am installing Stan and JAGS.

It looks like I have successfully installed JAGS but I cannot get rjags to install. So far I have tried installing from within RStudio, at terminal level, and compiling from source. Any suggestions would be appreciated.

Ubuntu 20.04

R 4.0.5

RStudio 1.4.1106

JAGS 4.3.0

rjags 4-10

**From within RStudio and at terminal level**
> install.packages("rjags")
Installing package into ‘/home/john/R/x86_64-pc-linux-gnu-library/4.0’
(as ‘lib’ is unspecified)
trying URL ''
Content type 'application/x-gzip' length 74060 bytes (72 KB)
downloaded 72 KB

* installing *source* package ‘rjags’ ...
** package ‘rjags’ successfully unpacked and MD5 sums checked
** using staged installation
checking for pkg-config... /usr/bin/pkg-config
configure: Setting compile and link flags according to pkg-config
configure: Compile flags are -I/usr/local/include/JAGS
configure: Link flags are -L/usr/local/lib -ljags
checking for gcc... gcc -std=gnu99
checking whether we are using the GNU C compiler... no
checking whether gcc -std=gnu99 accepts -g... no
checking for gcc -std=gnu99 option to accept ISO C89... unsupported
checking for jags_version in -ljags... yes
checking version of JAGS library... OK
configure: creating ./config.status
config.status: creating src/Makevars
configure: creating ./config.status
config.status: creating src/Makevars
config.status: creating R/unix/zzz.R
** libs
gcc -std=gnu99 -I"/usr/share/R/include" -DNDEBUG -I/usr/local/include/JAGS      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-tRgc13/r-base-4.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c init.c -o init.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I/usr/local/include/JAGS      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-tRgc13/r-base-4.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c -o jags.o
g++ -std=gnu++11 -I"/usr/share/R/include" -DNDEBUG -I/usr/local/include/JAGS      -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-tRgc13/r-base-4.0.5=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -g  -c -o parallel.o
g++ -std=gnu++11 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o init.o jags.o parallel.o -L/usr/local/lib -ljags -L/usr/lib/R/lib -lR
installing to /home/john/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-rjags/00new/rjags/libs
** R
** data
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded from temporary location
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 '/home/john/R/x86_64-pc-linux-gnu-library/4.0/00LOCK-rjags/00new/rjags/libs/': cannot open shared object file: No such file or directory
Error: loading failed
Execution halted
ERROR: loading failed
* removing ‘/home/john/R/x86_64-pc-linux-gnu-library/4.0/rjags’
Warning in install.packages :
  installation of package ‘rjags’ had non-zero exit status

** From source**

 tar xf rjags_4-10.tar.gz
john@john:~/Downloads$ cd rjags
john@john:~/Downloads/rjags$ ./configure
configure: error: "R_HOME is not defined"



It looks like I may be missing but, if so, I have no idea where to find it.

Have you tried installing jags from a system terminal?

sudo apt install jags

Yes, as far as I can see the output from within RStudio and the Systems Terminal are identical. Actually I forgot that there is a terminal option in RStudio.

Just to clarify, you have installed jags the system library right? I'm not referring to rjags the R package.

jags: /usr/local/bin/jags

Have you followed installation instructions?

2 Unix/Linux: pkg-config

If you have pkg-config installed then the configure script will use it
to detect the JAGS library and set the compiler and linker flags for
rjags. You can test this capability in a unix shell by typing

pkg-config --modversion jags

If this does not detect your JAGS installation then it means that the
file 'jags.pc' is not on the search path of pkg-config. In this case
you should add it by setting the environment variable PKG_CONFIG_PATH.
For example if the full path to 'jags.pc' is
'/usr/local/lib64/pkgconfig/jags.pc', then set

export PKG_CONFIG_PATH=/usr/local/lib64/pkgconfig

before installing rjags.

Recall that most Linux distributions divide software into user' and developer' versions, so if you are using a pre-built JAGS binary
package for your Linux distribution then remember to install the
developer version before attempting to install the rjags package.

john@john:~$ pkg-config --modversion jags

Seems to detect it.

Duh, I am not sure which JAGS I have installed. I was having problems with the installation yesterday plus a slightly wonky internet connection so tried three or four ways andi times but I think I finally installed from source.

I had not realized that the JAGS installation would make a difference when installing rjags.

Any suggestions on how to check this? I suppose, at worst, I can purge JAGS and make sure I install the developers' version if I can find it



After both I and my computer had a good night's sleep I ran

sudo apt-get update
sudo apt-get install r-cran-rjags

and rjags seems to be successfully installed.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.