tags:

views:

63

answers:

2

I am getting extraneous output in my .tex file that I can not suppress with <> or sink(). Notably, the unwanted lines are not enclosed by ..{Schunk} or similar.

This occurs for me when I use either DEoptim or rjags, although this is likely not limited to these functions.

example .Rnw file:

\documentclass[a4paper, 12]{article}
begin{document}

<<echo=FALSE>>=
require(DEoptim) 
Rosenbrock <- function(x){ #example from DEoptim authors 
  x1 <- x[1]
  x2 <- x[2]
  100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
lower <- c(-10,-10)
upper <- -lower
set.seed(1234)
DEoptim(Rosenbrock, lower, upper)

@

\end{document}

What I want to happen The result that I would like is the tex file that would be produced if the output were suppressed, or equivalently, if the code chunk were removed from the .Rnw file:

\documentclass[a4paper, 12]{article}
\usepackage{Sweave}
\begin{document}

\end{document}

What Happens However, the resulting .tex file has output from the function:

\documentclass[a4paper, 12]{article}
\usepackage{Sweave}
\begin{document}

Iteration: 1 bestvalit: 132.371451 bestmemit:   -1.851683    4.543355
Iteration: 2 bestvalit: 8.620563 bestmemit:   -1.854371    3.369908
....few hundred lines of DEoptim output ....
$member$storepop
list()


attr(,"class")
[1] "DEoptim"
\end{document}

Note that the output is not enclosed by \begin{Schunk} \end{Schunk}, so the $ signs confuse LaTeX and it won't compile.

+1  A: 

The output comes from the call to a compiled function (C or Fortran) in DEoptim.

This produces clean output:

\documentclass[a4paper, 12]{article}
\begin{document}

\section{Computation in R}

<<computation,results=hide>>=
require(DEoptim)
Rosenbrock <- function(x){
x1 <- x[1]
x2 <- x[2]
100 * (x2 - x1 * x1)^2 + (1 - x1)^2
}
lower <- c(-10,-10)
upper <- -lower
set.seed(1234)
res <- DEoptim(Rosenbrock, lower, upper)

@
\section{Results}

<<results>>=
res$optim

@
\end{document}

Henrik
Hi Henrik, I removed the results=tex from the code chunk. I use it in the actual document for use with xtable(), but removed the table from the example. The result is the same with or without it.
David
@Henrik: I have added an example of what I would like to see - all of the output from running the code suppressed. In the case of rjags the output is five pages of progress reports.
David
+1  A: 

Have you tried

<<echo=FALSE, results=hide>>

?

Kieran
That did it! Thanks.
David