Domanda

I have successfully created 2 tests slides in R Studio using the knitr package and pandoc. The R markdown file when using the "knitr" button in R studio looks fine and shows plots correctly, however when using pandoc to generate a .html file from the .Rmd file, running in the browser seems to lose all code wrapping and plots from the Rmd file. Here are my two scripts:

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)
```

and the script to run it:

# Load packages
setwd("~Documents")
require(knitr)
require(markdown)

# Create slides
knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.Rmd -o mdown.html')

also here is the html file generated by pandoc

<?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>

where am I going wrong here?

È stato utile?

Soluzione

You are processing the .Rmd file with pandoc where you should be processing the .md file created after running mdown.Rmd through knitr.

knit('mdown.Rmd')
system('pandoc -s -t slidy mdown.md -o mdown.html')

The .Rmd file is simply the original file you showed above.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top