Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (52 sloc) 1.68 KB
<!DOCTYPE html>
<html>
<head>
<title>A minimal knitr example in HTML</title>
</head>
<body>
<!--begin.rcode
library(knitr)
opts_chunk$set(fig.width=5, fig.height=5)
end.rcode-->
<p>This is a minimal example which shows <strong>knitr</strong>
working with HTML
pages. See <a href="https://rawgit.com/yihui/knitr-examples/master/003-minimal.html">here</a>
for the output and
<a href="https://github.com/yihui/knitr-examples/blob/master/003-minimal.Rhtml">here</a>
for the source.</p>
<p>Boring stuff as usual:</p>
<!--begin.rcode
## a simple calculator
1+1
## boring random numbers
set.seed(123)
rnorm(5)
end.rcode-->
<p>We can also produce plots (centered by the
option <code>fig.align='center'</code>):</p>
<!--begin.rcode html-cars-scatter, message=FALSE, fig.align='center'
library(ggplot2)
plot(mpg~hp, mtcars)
qplot(hp, mpg, data=mtcars)+geom_smooth()
end.rcode-->
<p>Errors, messages and warnings can be put into <code>div</code>'s
with different <code>class</code>es:</p>
<!--begin.rcode
sqrt(-1) # warning
message('knitr says hello to HTML!')
1+'a' # mission impossible
end.rcode-->
<p>In the end, let's show off a 3D plot from
the <strong>rgl</strong> package.</p>
<!--begin.rcode warning=FALSE
library(rgl)
knit_hooks$set(rgl = hook_rgl) # set up the hook first
end.rcode-->
<!--begin.rcode fancy-rgl, rgl=TRUE, fig.align='center', fig.width=4, fig.height=4, warning=FALSE
demo('bivar', package='rgl', echo=FALSE)
par3d(zoom=.7)
end.rcode-->
<p>Well, everything seems to be working. Let's ask R what is the
value of &pi;? Of course it is <!--rinline pi -->.</p>
</body>
</html>