In R and knitr, how do I build INLA results?

I am trying to include knitr in my document and print INLA graphics :

Using a trivial example

\documentclass{article}

\begin{document}

<<c1>>=
library("INLA")

n = 100
z = runif(n)
eta = 1 + 0.1*z
N = 20

p = exp(eta)/(1+exp(eta))
y = rbinom(n,  size = N, prob = p)
r = inla(y ~ 1 + z,  
         data = data.frame(y, z), 
         family = "binomial", 
         Ntrials = rep(N, n),
        control.family = list(link = "logit"), 
        control.predictor = list(compute=TRUE)
        )
@

<<c2>>=
plot(r, single=TRUE)
@

\end{document}

When I run this code interactively inside RStudio, everything works fine and I get a series of graphs. However, after knitting a document - not one of them is turned on.

How can i fix this?

UPDATE 1 I sent a question asking for clarification to the developer of the Google group package package .

UPDATE 2 INLA's Havard Rue posted a Sweave solution on Google Groups. Trick:

<<results=tex, echo=FALSE>>=
figs = plot(r, single=TRUE, postscript=TRUE, prefix="Sweave/ex1/figure-")

cat("\\begin{figure}[tbp]\n")
cat("\n")
cat("\\centering\n")

for(i in 1:length(figs)) {
    cat("\\includegraphics[width=7cm,height=7cm,angle=-90]{",
    gsub("[.]eps$","",figs[i]), "}\n", sep="")
}

cat("\\caption{XXX}\n")
cat("\\label{fig:11}\n")
cat("\\end{figure}\n")
@

. , pdf. , knitr, , .

+3
2

INLA, , . RStudio, (), . , , knitr , , knitr /.

, INLA,

<<>>=
op <- options(device="RStudioGD")
@

knitr

<<>>=
options(op)
@

( reset - ).

, INLA.

a >

INLA ( inla.dev.new), . , , -

noop <- function(...) NULL
assignInNamespace("inla.dev.new", noop, ns="INLA")

INLA.

+3

INLA

plot() (, ) . GUI/ RStudio.

Sweave, . , - . , , Sweave, , , . knitr/Sweave, - , /.

, Håvard Rue

www.r-inla.org

+2

All Articles