forked from yihui/knitr-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
003-minimal.Rhtml
64 lines (52 loc) · 1.68 KB
/
003-minimal.Rhtml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<!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 π? Of course it is <!--rinline pi -->.</p>
</body>
</html>