[英]knitr does not inject the R output into a pandoc/markdown documemt
I'm trying to use knitr
to inject R code and its output in pandoc/markdown
documents. 我正在尝试使用
knitr
在pandoc/markdown
文档中注入R代码及其输出。 But I do not get knitr to inject the R output. 但是我没有让knitr注入R输出。 I have tried decorating the R chunks with
r and with
{r}. 我尝试用
r and with
{r}装饰R块。 Both doesn't work. 两者都不起作用。 Here my sample setup (with ```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: 这是外壳程序的命令:
$ 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
. 运行命令后,确实得到了预期的新文件
foo.html
。 Here its content: 这里是它的内容:
<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没有注入执行R代码的输出。
What do I miss? 我想念什么? any help appreciated!
任何帮助表示赞赏!
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. 片状网站上提到的示例084和088中的R脚本已经说明了如何。 Please also take a look at the Rmd documents to learn the syntax for R code chunks in R Markdown.
还请查看Rmd文档,以了解R Markdown中R代码块的语法。 If you still have 5 minutes, watch the video on the homepage, and I think all the confusion should be gone.
如果您还有5分钟的时间,请观看首页上的视频,我认为所有的困惑都应该消除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.