我已使用knitr包和pandoc在R Studio中成功创建了2个测试幻灯片。在R studio中使用“knitr”按钮时的R markdown文件看起来很好并且正确显示了图表,但是当使用pandoc从.Rmd文件生成.html文件时,在浏览器中运行似乎丢失了所有代码包装和图表Rmd文件。这是我的两个脚本:
mdown.Rmd:
Title
========================================================
This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the **MD** toolbar button for help on Markdown).
When you click the **Knit HTML** button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
```{r}
summary(cars)
```
---
You can also embed plots, for example:
```{r fig.width=7, fig.height=6}
plot(cars)
```
以及运行它的脚本:
# Load packages
setwd("~Documents")
require(knitr)
require(markdown)
# Create slides
knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.Rmd -o mdown.html')
这里也是pandoc生成的html文件
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="generator" content="pandoc" />
<link rel="stylesheet" type="text/css" media="screen, projection, print"
href="http://www.w3.org/Talks/Tools/Slidy/slidy.css" />
<script src="http://www.w3.org/Talks/Tools/Slidy/slidy.js.gz"
charset="utf-8" type="text/javascript"></script>
</head>
<body>
<div class="slide">
<h1>Title</h1>
<p>This is an R Markdown document. Markdown is a simple formatting syntax for authoring web pages (click the <strong>MD</strong> toolbar button for help on Markdown).</p>
<p>When you click the <strong>Knit HTML</strong> button a web page will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:</p>
<p><code>{r} summary(cars)</code></p>
</div>
<div class="slide">
<p>You can also embed plots, for example:</p>
<p><code>{r fig.width=7, fig.height=6} plot(cars)</code></p>
</div>
</body>
</html>
我在哪里错了?
答案 0 :(得分:2)
您正在使用.Rmd
处理pandoc
文件,您应该在其中处理通过knitr运行.md
后创建的mdown.Rmd
文件。
knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.md -o mdown.html')
.Rmd
文件只是您在上面显示的原始文件。