title: How to compile a Latex document in Sweave without having to run rjags everytime?
body: <p>I am compiling a pdf using <code>sweave</code> and <code>latex</code> in <code>r</code>. I am running <code>rjags</code> for MCMC methods. Running these models take approximately an hour to converge. Every time I run my <code>sweave</code> code to compile a pdf, it also runs all the <code>jags</code> models again. This makes editing and finding out if I have made small syntax errors a pain if it takes an hour to compile the pdf. How do I keep all my variables generated by my <code>jags</code> code but not have <code>sweave</code> have to evaluate every time?
  The data can be found here: <a href="https://uwyo-files.instructure.com/courses/481850/files/36253354/course%20files/project4_genomebinom/chrgc.txt?download=1&amp;inline=1&amp;sf_verifier=ea3569eec1ca938fad4122a92e35ff57&amp;ts=1462863980&amp;user_id=569842" rel="nofollow noreferrer">https://uwyo-files.instructure.com/courses/481850/files/36253354/course%20files/project4_genomebinom/chrgc.txt?download=1&amp;inline=1&amp;sf_verifier=ea3569eec1ca938fad4122a92e35ff57&amp;ts=1462863980&amp;user_id=569842</a></p>
  
  <p>Here is some sample code</p>
  
  <pre><code> \documentclass[12pt, letterpaper]{article}
   \begin{document}
  
  &lt;&lt;computation,results=hide&gt;&gt;=
  humangc &lt;- read.csv("c:\\temp\\RtmpYpMfSP\\data15a4519241c1")
  chr&lt;-substr(humangc$chr, 4, 8)
  chr[chr=='X']&lt;-23
  chr[chr=='Y']&lt;-24
  chr&lt;-as.numeric(chr)
  humangc&lt;-data.frame(humangc[,-1], chr=chr)
  humangc&lt;-humangc[order(humangc$chr, humangc$bp),]  ### reorder data by chr
  
  ## drop NA data and blocks with fewer than 100000 (10%) valid data
  humangc&lt;-humangc[!is.na(humangc$valid) &amp; humangc$valid &gt; 100000,]
  
  
   ### hierarchical Bayesian model in JAGS
   bin.beta.beta&lt;-"
   model{
   for(i in 1:bins){
   gc[i] ~ dbinom(p[i], n[i])
   p[i] ~ dbeta(chrgc * chrprec, (1-chrgc)*chrprec)   
  }
  
  chrgc ~ dbeta(1,1)  ## chrgc is same as pi
  chrprec ~ dunif(0.001,10000)  ## chrprec is same as theta
  }
  "
  require(rjags)
  
  for(i in 1:24){
  data.jags&lt;-list(gc=humangc$gc[humangc$chr==i],
                  n=humangc$valid[humangc$chr==i],
                  bins=length(humangc$gc[humangc$chr==i]) )
  
  mod.jags&lt;-   jags.model(textConnection(bin.beta.beta),data=data.jags,n.chains=3,n.adapt=1000)
  
  mod.samples&lt;-jags.samples(model=mod.jags, variable.names=c("chrgc", "chrprec"), n.iter=5000,thin=2)
  ###  summarize quantiles of beta and p-values of empirical obs from Beta
  
  gcest&lt;-NULL
  
  gcest$q&lt;-qbeta(c(0.025, 0.5, 0.975),
                 mean(mod.samples$chrprec[1,,] * mod.samples$chrgc[1,,]),
                 mean(mod.samples$chrprec[1,,] * (1-mod.samples$chrgc[1,,])) )
  gcest$p&lt;-pbeta(humangc$perc[humangc$chr==i], 
                 mean(mod.samples$chrprec[1,,] * mod.samples$chrgc[1,,]),
                 mean(mod.samples$chrprec[1,,] * (1-mod.samples$chrgc[1,,])) )
  gcest$perc &lt;- humangc$perc[humangc$chr==i]
  gcest$bp &lt;- humangc$bp[humangc$chr==i]
  ## write workspace for chromosome to disk
  save.image(paste("Rworkspace_chr", i, sep=""))
    }
  @
  
  
  &lt;&lt;echo=F, fig=T, include=F&gt;&gt;=
  update(mod.jags)
  require(coda)
  params &lt;- c("chrgc", "chrprec")
  samps &lt;- coda.samples(mod.jags, params, n.iter = 2000)
  plot(samps)
  @
  SOME TRIVIAL TEXT!!!!!!
  end{document}
  </code></pre>
  
  <p>As you can see I am creating 24 different models. Which takes a little while. How do I get "SOME TRIVIAL TEXT!!!!!!!" to show up quick when I compile the pdf, given that I need the variables created by <code>jags</code>?</p>
  
  <p><a href="https://i.stack.imgur.com/sj3kD.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sj3kD.jpg" alt="enter image description here"></a></p>
  
  <p>The step above takes a while.</p>