9

我的 .tex 文件中出现了无法使用 <> 或 sink() 抑制的无关输出。值得注意的是,不需要的行不包含在 ..{Schunk} 或类似内容中。

当我使用 DEoptim 或 rjags 时,会发生这种情况,尽管这可能不限于这些功能。

.Rnw 文件示例:

\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}

我想要发生 的结果我想要的结果是,如果输出被抑制,或者等效地,如果从 .Rnw 文件中删除代码块,则会生成 tex 文件:

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

\end{document}

发生了什么 但是,生成的 .tex 文件具有函数的输出:

\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}

请注意,输出没有包含在 \begin{Schunk} \end{Schunk} 中,因此 $ 符号会混淆 LaTeX 并且不会编译。

4

2 回答 2

8

你有没有尝试过

<<echo=FALSE, results=hide>>

?

于 2010-10-22T00:57:54.423 回答
7

输出来自对 DEoptim 中编译函数(C 或 Fortran)的调用。

这会产生干净的输出:

\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 &lt;- c(-10,-10)  
upper &lt;- -lower  
set.seed(1234)  
res &lt;- DEoptim(Rosenbrock, lower, upper)  

@  
\section{Results}  

<<results>>=  
res$optim  


@  
\end{document}  
于 2010-10-21T20:27:32.053 回答