3

I'm having an issue getting rjags to load & run. I can install rjags, but it doesn't run because it can't find JAGS. My versions are listed below and are all updated to the latest versions. I'm also using a Thinkpad. JAGS Version: 4.3.0 RStudio Version: 2021.09.0 Build 351 Installation of rjags is okay using the following command: install.packages('rjags',configure.args="--enable-rpath")

Error messages recopied below:

library(rjags)
Warning: package ‘rjags’ was built under R version 4.0.5
Error: package or namespace load failed for ‘rjags’:
 .onLoad failed in loadNamespace() for 'rjags', details:
  call: fun(libname, pkgname)
  error: The environment variable JAGS_HOME is set to
C:/ProgramData/Microsoft/Windows/Start Menu/Programs/JAGS/JAGS-4.3.0
but no JAGS installation can be found there

If I go to where JAGS is installed, the path is:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\JAGS

I used the above lines shared to try and solve this problem, but to no avail:

Sys.setenv(JAGS_HOME="C:/ProgramData/Microsoft/Windows/Start Menu/Programs/JAGS/JAGS-4.3.0") 
Error: unexpected '/' in "Sys.setenv(JAGS_HOME=C:/"

Corrected to:

Sys.setenv(JAGS_HOME="C:\ProgramData\Microsoft\Windows\Start Menu\Programs\JAGS\JAGS-4.3.0") 
Error: '\P' is an unrecognized escape in character string starting ""C:\P"

Corrected to:

Sys.setenv(JAGS_HOME="C:\ ProgramData\ Microsoft\ Windows\ Start Menu\ Programs\ JAGS\ JAGS-4.3.0") 

This doesn't yield any errors, but when I try to load rjags I get the following:

library(rjags) 
Warning: package ‘rjags’ was built under R version 4.0.5
Error: package or namespace load failed for ‘rjags’:
 .onLoad failed in loadNamespace() for 'rjags', details:
  call: fun(libname, pkgname)
  error: The environment variable JAGS_HOME is set to
C: ProgramData Microsoft Windows Start Menu Programs JAGS JAGS-4.3.0
but no JAGS installation can be found there

This is the same as above, but the / are left out for some reason.

Unsure of what to try next, any thoughts/insight would be much appreciated! :)

This seems to be an issue others have faced too: rjags failed to load and R Failed to locate any version of JAGS https://sourceforge.net/p/mcmc-jags/discussion/610037/thread/060fd5c378/?limit=25 https://www.reddit.com/r/rstats/comments/pzto5t/rjags_is_my_enemy/

Though none of these solutions seem to be working (yet?).

nicola
  • 24,005
  • 3
  • 35
  • 56
  • Use the double backslash: `Sys.setenv(JAGS_HOME="C:\\ProgramData\\Microsoft\\Windows\\Start Menu\\Programs\\JAGS\\JAGS-4.3.0")` – nicola Oct 13 '21 at 16:00
  • I doubt that JAGS is installed in the `Start Menu/Programs` folder. This folder normally contains only some shortcuts. – Stéphane Laurent Oct 13 '21 at 16:03

1 Answers1

2

Problem solved!

Both of you were right - JAGS was in an odd location, so I moved it to:

C:\Program Files\JAGS\JAGS-4.3.0

And then used the code (I think / is the same as \):

Sys.setenv(JAGS_HOME="C:/Program Files/JAGS/JAGS-4.3.0")

And now it works like a charm :)

  • 1
    Indeed there seems to be a problem with the latest version (4.3.1). Installing the older version and setting `Sys.setenv` solves the issue. `library(rjags)` would link the JAGS automatically. – Yang Liu Sep 26 '22 at 21:02