0

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 ファイルを実行しています

4

1 に答える 1

2

あなたはknitrではなくSweaveを実行しているようです。RStudio でグローバル オプションまたはプロジェクト オプションをチェックして、どちらが選択されているかを確認します。

于 2016-05-27T11:01:05.707 に答える