I'm trying to use knitr
to inject R code and its output in pandoc/markdown
documents. But I do not get knitr to inject the R output. I have tried decorating the R chunks with r and with
{r}. Both doesn't work. Here my sample setup (with ```r):
我正在尝试使用knitr在pandoc / markdown文档中注入R代码及其输出。但我没有得到编织R输出的编织。我尝试用r和{r}来装饰R块。两者都不起作用。在这里我的示例设置(使用```r):
First I show the command I issue, then I list the two files subsequently used by this command.
首先我展示我发出的命令,然后列出该命令随后使用的两个文件。
Here the command for the shell:
这里是shell的命令:
$ r CMD BATCH knitme.R
$ r CMD BATCH knitme.R
Content of knitme.R
:
knitme.R的内容:
library("knitr")
pandoc("foo.md")
Content of 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?
After I ran the command I do get, as expected a new file foo.html
. Here its content:
在我运行命令之后,我确实得到了一个新文件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>
This result shows that pandoc converted the input file foo.md
, *but knitr did not inject the Output of the execeutes R code.
这个结果表明pandoc转换了输入文件foo.md,*但是knitr没有注入execeutes R代码的输出。
What do I miss? any help appreciated!
我错过了什么?任何帮助赞赏!
1 个解决方案
#1
1
You should first call knit()
on an R Markdown (*.Rmd
) document, which produces a Markdown (*.md
) document, and that is when you can run pandoc()
.
您应首先在R Markdown(* .Rmd)文档上调用knit(),该文档生成Markdown(* .md)文档,这时您可以运行pandoc()。
library(knitr)
knit('foo.Rmd')
pandoc('foo.md')
The R scripts in examples 084 and 088 as mentioned on the flaky website have illustrated how. Please also take a look at the Rmd documents to learn the syntax for R code chunks in R Markdown. If you still have 5 minutes, watch the video on the homepage, and I think all the confusion should be gone.
在片状网站上提到的示例084和088中的R脚本已经说明了如何。另请参阅Rmd文档以了解R Markdown中R代码块的语法。如果你还有5分钟,请在主页上观看视频,我认为所有的困惑都应该消失。
#1
1
You should first call knit()
on an R Markdown (*.Rmd
) document, which produces a Markdown (*.md
) document, and that is when you can run pandoc()
.
您应首先在R Markdown(* .Rmd)文档上调用knit(),该文档生成Markdown(* .md)文档,这时您可以运行pandoc()。
library(knitr)
knit('foo.Rmd')
pandoc('foo.md')
The R scripts in examples 084 and 088 as mentioned on the flaky website have illustrated how. Please also take a look at the Rmd documents to learn the syntax for R code chunks in R Markdown. If you still have 5 minutes, watch the video on the homepage, and I think all the confusion should be gone.
在片状网站上提到的示例084和088中的R脚本已经说明了如何。另请参阅Rmd文档以了解R Markdown中R代码块的语法。如果你还有5分钟,请在主页上观看视频,我认为所有的困惑都应该消失。