【发布时间】:2013-11-15 00:11:56
【问题描述】:
我正在尝试使用knitr 将R 代码及其输出注入pandoc/markdown 文档中。但我没有让 knitr 注入 R 输出。我尝试用r and with{r} 装饰 R 块。两者都不起作用。这是我的示例设置(使用```r):
首先显示我发出的命令,然后列出该命令随后使用的两个文件。
这里是shell的命令:
$ r CMD BATCH knitme.R
knitme.R的内容:
library("knitr")
pandoc("foo.md")
foo.md的内容:
# My knitr test
```r
1+1
```
Did this print *the result* as well?
Here a graph:
```r
plot(1:10)
```
And where is the graph?
运行命令后,我确实得到了一个新文件foo.html。这里是它的内容:
<h1 id="my-knitr-test">My knitr test</h1>
<pre class="sourceCode r"><code class="sourceCode r"><span class="dv">1+1</span></code></pre>
<p>Did this print <em>the result</em> as well?</p>
<p>Here a graph:</p>
<pre class="sourceCode r"><code class="sourceCode r">
<span class="kw">plot</span>(<span class="dv">1</span>:<span class="dv">10</span>)</code></pre>
<p>And where is the graph?</p>
这个结果表明pandoc转换了输入文件foo.md,*但是knitr没有注入执行R代码的输出。
我错过了什么?任何帮助表示赞赏!
【问题讨论】:
-
您的文档中没有任何 knitr 代码块。 R markdown 中的 knitr 代码块应以 ```{r} 开头
-
好的,我也尝试过使用```{r},但是我在html输出中得到了“{r}”,而且仍然没有从knitr注入R输出。 - 我真的不明白:Yihui describes exactly my approach(注意:网站很不稳定)。
标签: r knitr pandoc r-markdown