[R] cacheSweave fails when used in conjunction with rjags

Roger Levy rlevy at ling.ucsd.edu
Fri Mar 26 06:57:14 CET 2010

Hi all,

I use the excellent packages rjags and cacheSweave, and unfortunately  
seem to have found an incompatibility between them.  Below are a  
minimal .Rnw file and corresponding JAGS model file which illustrate  
the problem:

*** JAGS model file; name=j.bug ***
model {
   mu ~ dnorm(0,1.0E-5)
   sigma ~ dunif(0,100)
   for(i in 1:length(y)) {
     y[i] ~ dnorm(mu,sigma)

*** .Rnw file; name=testCacheSweave-jags.Rnw ***



y <- rnorm(100)
m <- jags.model("j.bug")
res <- coda.samples(m,c("mu","sigma"),n.iter=1000)


When I run Sweave with cacheSweaveDriver, I get the following error  
(note that this happens on the first invocation, not just on repeat  

 > Sweave("testCacheSweave-jags.Rnw",driver=cacheSweaveDriver)
Writing to file testCacheSweave-jags.tex
Processing code chunks ...
  1 : echo term verbatim (label=loadLib)
  2 : echo term verbatim (label=testJags)

Error:  chunk 2 (label=testJags)
Error in jags.model("j.bug") : RUNTIME ERROR:
Unable to evaluate upper index of counter i

Reading through the cacheSweave documentation, it remains unclear to  
me why this error would occur.  Would anyone be able to clarify, and/ 
or suggest a possible workaround?  It's an unfortunate conflict  
because running JAGS models is one of the most computation-intensive  
operations that I have in my .Rnw document.

Best & many thanks in advance.



Roger Levy                      Email: rlevy at ling.ucsd.edu
Assistant Professor             Phone: 858-534-7219
Department of Linguistics       Fax:   858-534-4789
UC San Diego                    Web:   http://ling.ucsd.edu/~rlevy

More information about the R-help mailing list