如何抑制未通过 echo=FALSE 抑制的 Sweave 输出?
我在 .tex 文件中收到了无法使用 <> 抑制的无关输出。或接收器()。值得注意的是,不需要的行不会被 ..{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 并且无法编译。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你尝试过吗
?
Have you tried
?
输出来自对 DEoptim 中编译函数(C 或 Fortran)的调用。
这会产生干净的输出:
The output comes from the call to a compiled function (C or Fortran) in DEoptim.
This produces clean output: