如何抑制未被echo = FALSE抑制的Sweave输出?

时间:2022-11-28 14:07:29

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.

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

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

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

example .Rnw file:

示例.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}

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:

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

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

\end{document}

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

发生了什么但是,生成的.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}

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

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

2 个解决方案

#1


7  

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

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

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

@  
\section{Results}  

<<results>>=  
res$optim  


@  
\end{document}  

#2


7  

Have you tried

你有没有尝试过

<<echo=FALSE, results=hide>>

?

#1


7  

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

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

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

@  
\section{Results}  

<<results>>=  
res$optim  


@  
\end{document}  

#2


7  

Have you tried

你有没有尝试过

<<echo=FALSE, results=hide>>

?