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 ***
\documentclass[12pt]{article}
\usepackage{Sweave}

\begin{document}

<<loadLib>>=
library(rjags)
@

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

<<plotResults,fig=T>>=
plot(res)
@
\end{document}
***


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

> 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


--

Roger Levy                      Email: rl...@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

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to