66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
		
		
			
		
	
	
			66 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
	
	
|   | <!DOCTYPE html> | ||
|  | <html> | ||
|  | <head> | ||
|  |   <title>A minimal knitr example in HTML</title> | ||
|  | </head> | ||
|  | <body> | ||
|  | 
 | ||
|  |   <!--begin.rcode | ||
|  |       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://bitbucket.org/stat/knitr/downloads/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 | ||
|  |     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 | ||
|  |     if (require('rgl')) { | ||
|  |     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> |