繁体   English   中英

如何在rnw文件中使用Knitr使用条件评估

[英]How to use conditional eval using Knitr in a rnw file

我想使用knitr对rnw文件中的代码块使用条件评估。

当我运行官方示例时:knitr-examples / 011-conditional-eval.Rnw

\documentclass{article}

\begin{document}
\SweaveOpts{concordance=TRUE}

<<controller>>=
# this variable controls if a chunk should be evaluated
dothis <- TRUE
@

<<chunk1, eval = dothis>>=
print('say hello world')
@

<<chunk2, eval = !dothis>>=
print('silence is gold')
@

\end{document}

我收到以下错误:

Writing to file test.tex
Processing code chunks with options ...
 1 : echo keep.source term verbatim (label = controller, test.Rnw:6)
Error in check(options) : invalid value for 'eval' : dothis
Calls: <Anonymous> -> SweaveParseOptions -> check
Execution halted

我究竟做错了什么? 我正在使用Rstudio运行rnw文件

您似乎正在运行Sweave,而不是knitr。 在RStudio中检查您的全局或项目选项,以查看选择了哪个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM