]> git.lyx.org Git - lyx.git/blob - lib/examples/sweave.lyx
Update manual from Ignatio
[lyx.git] / lib / examples / sweave.lyx
1 #LyX 2.0.0svn created this file. For more info see http://www.lyx.org/
2 \lyxformat 410
3 \begin_document
4 \begin_header
5 \textclass article
6 \use_default_options true
7 \begin_modules
8 sweave
9 \end_modules
10 \maintain_unincluded_children false
11 \language english
12 \inputencoding auto
13 \fontencoding global
14 \font_roman lmodern
15 \font_sans lmss
16 \font_typewriter lmtt
17 \font_default_family default
18 \use_non_tex_fonts false
19 \font_sc false
20 \font_osf false
21 \font_sf_scale 100
22 \font_tt_scale 100
23
24 \graphics default
25 \default_output_format default
26 \output_sync 0
27 \bibtex_command default
28 \index_command default
29 \paperfontsize default
30 \spacing single
31 \use_hyperref false
32 \papersize default
33 \use_geometry false
34 \use_amsmath 1
35 \use_esint 1
36 \use_mhchem 1
37 \use_mathdots 1
38 \cite_engine basic
39 \use_bibtopic false
40 \use_indices false
41 \paperorientation portrait
42 \suppress_date false
43 \use_refstyle 0
44 \index Index
45 \shortcut idx
46 \color #008000
47 \end_index
48 \secnumdepth 3
49 \tocdepth 3
50 \paragraph_separation skip
51 \defskip medskip
52 \quotes_language english
53 \papercolumns 1
54 \papersides 1
55 \paperpagestyle default
56 \tracking_changes false
57 \output_changes false
58 \html_math_output 0
59 \html_be_strict false
60 \end_header
61
62 \begin_body
63
64 \begin_layout Title
65 A Test File
66 \end_layout
67
68 \begin_layout Author
69 Friedrich Leisch
70 \begin_inset Foot
71 status collapsed
72
73 \begin_layout Plain Layout
74 LyX 
75 \begin_inset Quotes eld
76 \end_inset
77
78 port
79 \begin_inset Quotes erd
80 \end_inset
81
82  by Gregor Gorjanc
83 \end_layout
84
85 \end_inset
86
87
88 \end_layout
89
90 \begin_layout Standard
91 A simple example that will run in any S engine: The integers from 1 to 10
92  are
93 \end_layout
94
95 \begin_layout Chunk
96 <<print=TRUE>>=
97 \end_layout
98
99 \begin_layout Chunk
100 1:10 
101 \end_layout
102
103 \begin_layout Chunk
104 <<results=hide>>=
105 \end_layout
106
107 \begin_layout Chunk
108 print(1:20)
109 \end_layout
110
111 \begin_layout Chunk
112 @ % the above is just to ensure that 2 code chunks can follow each other
113 \end_layout
114
115 \begin_layout Standard
116 We can also emulate a simple calculator: 
117 \end_layout
118
119 \begin_layout Chunk
120 <<echo=TRUE,print=TRUE>>=
121 \end_layout
122
123 \begin_layout Chunk
124 1 + 1 
125 \end_layout
126
127 \begin_layout Chunk
128 1 + pi
129 \end_layout
130
131 \begin_layout Chunk
132 sin(pi/2)
133 \end_layout
134
135 \begin_layout Chunk
136 @
137 \end_layout
138
139 \begin_layout Standard
140 Now we look at Gaussian data:
141 \end_layout
142
143 \begin_layout Chunk
144 <<>>=
145 \end_layout
146
147 \begin_layout Chunk
148 library(stats)
149 \end_layout
150
151 \begin_layout Chunk
152 x <- rnorm(20)
153 \end_layout
154
155 \begin_layout Chunk
156 print(x)
157 \end_layout
158
159 \begin_layout Chunk
160 print(t1 <- t.test(x))
161 \end_layout
162
163 \begin_layout Chunk
164 @
165 \end_layout
166
167 \begin_layout Standard
168 Note that we can easily integrate some numbers into standard text: The third
169  element of vector 
170 \family typewriter
171 x
172 \family default
173  is 
174 \begin_inset Flex S/R expression
175 status collapsed
176
177 \begin_layout Plain Layout
178
179 x[3]
180 \end_layout
181
182 \end_inset
183
184 , the 
185 \begin_inset Formula $p$
186 \end_inset
187
188 -value of the test is 
189 \begin_inset Flex S/R expression
190 status collapsed
191
192 \begin_layout Plain Layout
193
194 format.pval(t1$p.value)
195 \end_layout
196
197 \end_inset
198
199
200 \end_layout
201
202 \begin_layout Standard
203
204 \family roman
205 \series medium
206 \shape up
207 \size normal
208 \emph off
209 \bar no
210 \noun off
211 \color none
212 Now we look at a summary of the famous iris dataset, and we want to see
213  the commands in the code chunks:
214 \end_layout
215
216 \begin_layout Standard
217 \begin_inset Flex Sweave Options
218 status open
219
220 \begin_layout Plain Layout
221
222 echo=true,keep.source=true
223 \end_layout
224
225 \end_inset
226
227
228 \end_layout
229
230 \begin_layout Chunk
231 <<engine=R>>=
232 \end_layout
233
234 \begin_layout Chunk
235 # A comment
236 \end_layout
237
238 \begin_layout Chunk
239 data(iris)
240 \end_layout
241
242 \begin_layout Chunk
243 summary(iris)
244 \end_layout
245
246 \begin_layout Chunk
247 @ % def
248 \end_layout
249
250 \begin_layout Standard
251 \begin_inset Float figure
252 placement tbph
253 wide false
254 sideways false
255 status open
256
257 \begin_layout Plain Layout
258 \noindent
259 \align center
260 \begin_inset ERT
261 status open
262
263 \begin_layout Plain Layout
264
265 <<fig=TRUE>>=
266 \end_layout
267
268 \begin_layout Plain Layout
269
270 library(graphics)
271 \end_layout
272
273 \begin_layout Plain Layout
274
275 pairs(iris)
276 \end_layout
277
278 \begin_layout Plain Layout
279
280 @
281 \end_layout
282
283 \end_inset
284
285
286 \end_layout
287
288 \begin_layout Plain Layout
289 \begin_inset Caption
290
291 \begin_layout Plain Layout
292 Pairs plot of the iris data.
293 \end_layout
294
295 \end_inset
296
297
298 \end_layout
299
300 \end_inset
301
302
303 \end_layout
304
305 \begin_layout Standard
306 \begin_inset Float figure
307 placement tbph
308 wide false
309 sideways false
310 status open
311
312 \begin_layout Plain Layout
313 \noindent
314 \align center
315 \begin_inset ERT
316 status open
317
318 \begin_layout Plain Layout
319
320 <<fig=true>>=
321 \end_layout
322
323 \begin_layout Plain Layout
324
325 boxplot(Sepal.Length~Species,data=iris)
326 \end_layout
327
328 \begin_layout Plain Layout
329
330 @
331 \end_layout
332
333 \end_inset
334
335
336 \end_layout
337
338 \begin_layout Plain Layout
339 \begin_inset Caption
340
341 \begin_layout Plain Layout
342 Boxplot of sepal length grouped by species.
343 \end_layout
344
345 \end_inset
346
347
348 \end_layout
349
350 \end_inset
351
352
353 \end_layout
354
355 \begin_layout Chunk
356 <<engine=S4>>=
357 \end_layout
358
359 \begin_layout Chunk
360 function.that.comes.only.with.Splus(x)
361 \end_layout
362
363 \begin_layout Chunk
364 @
365 \end_layout
366
367 \begin_layout Standard
368 \begin_inset Float figure
369 wide false
370 sideways false
371 status open
372
373 \begin_layout Plain Layout
374 \noindent
375 \align center
376 \begin_inset ERT
377 status open
378
379 \begin_layout Plain Layout
380
381 <<fig=true>>=
382 \end_layout
383
384 \begin_layout Plain Layout
385
386 boxplot(Sepal.Length~Species,data=iris)
387 \end_layout
388
389 \begin_layout Plain Layout
390
391 @
392 \end_layout
393
394 \end_inset
395
396
397 \end_layout
398
399 \begin_layout Plain Layout
400 \begin_inset Caption
401
402 \begin_layout Plain Layout
403 Boxplot of sepal length grouped by species
404 \end_layout
405
406 \end_inset
407
408
409 \end_layout
410
411 \end_inset
412
413
414 \end_layout
415
416 \end_body
417 \end_document