| 1 |
<!DOCTYPE html> |
| 2 |
<html> |
| 3 |
<!-- |
| 4 |
%\VignetteEngine{knitr::knitr_notangle} |
| 5 |
%\VignetteIndexEntry{An R HTML Vignette with knitr} |
| 6 |
--> |
| 7 |
<head> |
| 8 |
<meta charset="utf-8"> |
| 9 |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
| 10 |
<style type="text/css"> |
| 11 |
body,td{width:800px;margin:auto;} |
| 12 |
</style> |
| 13 |
<title>An R HTML vignette with knitr</title> |
| 14 |
</head> |
| 15 |
<!--begin.rcode setup, include=FALSE |
| 16 |
library(knitr) |
| 17 |
# to base64 encode images |
| 18 |
opts_knit$set(upload.fun = image_uri) |
| 19 |
end.rcode--> |
| 20 |
|
| 21 |
<body> |
| 22 |
|
| 23 |
<p>This is an R HTML vignette. The file extension is <code>*.Rhtml</code>, and |
| 24 |
it has to include a special comment to tell R that this file needs to be |
| 25 |
compiled by <strong>knitr</strong>:</p> |
| 26 |
|
| 27 |
<pre><!-- |
| 28 |
%\VignetteEngine{knitr::knitr} |
| 29 |
%\VignetteIndexEntry{The Title of Your Vignette} |
| 30 |
--> |
| 31 |
</pre> |
| 32 |
|
| 33 |
<p>Now you can write R code chunks:</p> |
| 34 |
|
| 35 |
<!--begin.rcode cars-demo |
| 36 |
summary(cars) |
| 37 |
fit=lm(dist~speed, data=cars) |
| 38 |
summary(fit) |
| 39 |
end.rcode--> |
| 40 |
|
| 41 |
<p>You can also embed plots, for example:</p> |
| 42 |
|
| 43 |
<!--begin.rcode cars-plot, fig.width=7, fig.height=6, fig.align='center' |
| 44 |
par(mar=c(4,4,.1,.1)) |
| 45 |
plot(cars, pch=19) |
| 46 |
end.rcode--> |
| 47 |
|
| 48 |
<p>For package vignettes, you need to encode images in base64 strings using the |
| 49 |
<code>knitr::image_uri()</code> function so that the image files are no longer |
| 50 |
needed after the vignette is compiled. For example, you can add this chunk in |
| 51 |
the beginning of a vignette:</p> |
| 52 |
|
| 53 |
<!--begin.rcode setup, eval=FALSE |
| 54 |
end.rcode--> |
| 55 |
|
| 56 |
</body> |
| 57 |
</html> |