0

Seems that runjags suddenly (after update to version 2.0.3-2) has trouble finding JAGS binary, issuing an error:

[1] "Error in system(\"where jags\", intern = TRUE) : 'where' not found\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in system("where jags", intern = TRUE): 'where' not found

I fixed this by putting this line to my Rprofile:

.runjags.options <- list(jagspath = "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe")

This pretty much fixes the problem (although it is not ideal - previous versions of runjags could find the binary automatically).

However, when the Rgui (in Windows XP) is launched by opening an .Rdata file, which is associated to it, it stops working:

> .runjags.options # it was set in the Rprofile
$jagspath
[1] "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe"

> require(runjags)
Loading required package: runjags
Warning message:
package ‘runjags’ was built under R version 3.1.3 
> runjags.getOption("jagspath")
[1] "Error in system(\"where jags\", intern = TRUE) : 'where' not found\n"
attr(,"class")
[1] "try-error"
attr(,"condition")
<simpleError in system("where jags", intern = TRUE): 'where' not found

Is this a bug? How to fix this?

I am currently calling runjags.options(jagspath = "c:/Program Files/JAGS/JAGS-4.2.0/i386/bin/jags-terminal.exe") in my source after require(runjags), but I would like to avoid this as much as possible!

Tomas
  • 57,621
  • 49
  • 238
  • 373

1 Answers1

1

The problem is in the findjags() function, more specifically use of the 'where' system command which was added to Windows in 2003 and therefore doesn't exist in Windows XP. There is some code in findjags() that is designed to detect earlier versions of Windows and revert to a different method of finding JAGS, but this hasn't changed since version 1.x so I don't know why this has 'suddenly' stopped working. Perhaps there has been a change in your system, or a change in the way the system() command works in R. I have modified this code to work around where I think the error is coming from, but I don't have access to Windows XP (I'm rather surprised that you do!) so I can't test it. I don't think it will do any harm though so I will include it in the next release anyway, after testing on more recent versions of Windows.

I also don't know exactly why the .runjags.options is not being found when you open a .Rdata file, but it is possible that opening a .Rdata file loads the library before setting objects. I will look into this but it is likely not something I can do anything about. The alternative to using runjags.options() is to set the jags argument in calls to run.jags etc.

Matt Denwood
  • 2,537
  • 1
  • 12
  • 16
  • Thanks Matt. *"but it is possible that opening a .Rdata file loads the library before setting objects"* - I don't think so - if you look at the console session in my question (the opening of .Rdata file), you see that the library is being loaded by the `require(runjags)` *after* I checked that `.runjags.options` is set correctly. So it must be somewhere in the runjags library then? – Tomas Nov 12 '16 at 18:25
  • I don't think so - I can't reproduce the error you describe when opening a .Rdata file and there is really nothing in runjags to distinguish how R was opened. The code is: setopts <- mget('.runjags.options', envir=.GlobalEnv, ifnotfound=list(.runjags.options=NULL))[[1]] and then a test for is.null(setopts) (look in zzz.R) - does this code work for you (i.e. setopts is not NULL) after opening a .Rdata file? If that doesn't help please send a reproducible example of how you are generating this error to m: my contact details are on CRAN / inside packageDescription('runjags'). – Matt Denwood Nov 13 '16 at 14:46