Debian Codegraph @

inst/examples/knitr-beamer.lyx

raw
1 #LyX 2.1 created this file. For more info see http://www.lyx.org/
2 \lyxformat 474
3 \begin_document
4 \begin_header
5 \textclass beamer
6 \begin_preamble
7 \usetheme{PaloAlto}
8 \end_preamble
9 \use_default_options true
10 \begin_modules
11 knitr
12 \end_modules
13 \maintain_unincluded_children false
14 \language english
15 \language_package none
16 \inputencoding default
17 \fontencoding global
18 \font_roman default
19 \font_sans default
20 \font_typewriter default
21 \font_math auto
22 \font_default_family default
23 \use_non_tex_fonts false
24 \font_sc false
25 \font_osf false
26 \font_sf_scale 100
27 \font_tt_scale 100
28 \graphics default
29 \default_output_format default
30 \output_sync 0
31 \bibtex_command default
32 \index_command default
33 \paperfontsize 10
34 \spacing single
35 \use_hyperref true
36 \pdf_bookmarks true
37 \pdf_bookmarksnumbered false
38 \pdf_bookmarksopen false
39 \pdf_bookmarksopenlevel 1
40 \pdf_breaklinks false
41 \pdf_pdfborder true
42 \pdf_colorlinks false
43 \pdf_backref false
44 \pdf_pdfusetitle true
45 \papersize default
46 \use_geometry true
47 \use_package amsmath 1
48 \use_package amssymb 1
49 \use_package cancel 1
50 \use_package esint 1
51 \use_package mathdots 1
52 \use_package mathtools 1
53 \use_package mhchem 1
54 \use_package stackrel 1
55 \use_package stmaryrd 1
56 \use_package undertilde 1
57 \cite_engine basic
58 \cite_engine_type default
59 \biblio_style plain
60 \use_bibtopic false
61 \use_indices false
62 \paperorientation portrait
63 \suppress_date false
64 \justification true
65 \use_refstyle 1
66 \index Index
67 \shortcut idx
68 \color #008000
69 \end_index
70 \secnumdepth 3
71 \tocdepth 3
72 \paragraph_separation indent
73 \paragraph_indentation default
74 \quotes_language english
75 \papercolumns 1
76 \papersides 1
77 \paperpagestyle default
78 \tracking_changes false
79 \output_changes false
80 \html_math_output 0
81 \html_css_as_file 0
82 \html_be_strict false
83 \end_header
84
85 \begin_body
86
87 \begin_layout Standard
88 \begin_inset ERT
89 status open
90
91 \begin_layout Plain Layout
92
93 <<setup, include=FALSE>>=
94 \end_layout
95
96 \begin_layout Plain Layout
97
98 library(knitr)
99 \end_layout
100
101 \begin_layout Plain Layout
102
103 opts_chunk$set(fig.path='figure/beamer-',fig.align='center',fig.show='hold',size='f
104 ootnotesize')
105 \end_layout
106
107 \begin_layout Plain Layout
108
109 @
110 \end_layout
111
112 \end_inset
113
114
115 \end_layout
116
117 \begin_layout Title
118 \begin_inset Argument 1
119 status collapsed
120
121 \begin_layout Plain Layout
122 knitr, Beamer, and FragileFrame
123 \end_layout
124
125 \end_inset
126
127 A Minimal Demo of knitr with Beamer and Fragile Frames
128 \end_layout
129
130 \begin_layout Author
131 Yihui Xie
132 \begin_inset Foot
133 status open
134
135 \begin_layout Plain Layout
136 I thank Richard E.
137 Goldberg for providing this demo.
138 \end_layout
139
140 \end_inset
141
142
143 \end_layout
144
145 \begin_layout Frame
146 \begin_inset Argument 4
147 status open
148
149 \begin_layout Plain Layout
150 Background
151 \end_layout
152
153 \end_inset
154
155
156 \end_layout
157
158 \begin_deeper
159 \begin_layout Itemize
160 The
161 \series bold
162 knitr
163 \emph on
164
165 \series default
166 \emph default
167 package allows you to embed R code and figures in LaTeX documents
168 \end_layout
169
170 \begin_deeper
171 \begin_layout Itemize
172 It has functionality similar to Sweave but looks nicer and gives you more
173 control
174 \end_layout
175
176 \end_deeper
177 \begin_layout Itemize
178 If you already have Sweave working in LyX, getting
179 \series bold
180 knitr
181 \series default
182 to work is trivial
183 \end_layout
184
185 \begin_deeper
186 \begin_layout Enumerate
187 Install the
188 \series bold
189 knitr
190 \series default
191 package in
192 \emph on
193 R
194 \end_layout
195
196 \begin_layout Enumerate
197 Read
198 \begin_inset Flex URL
199 status collapsed
200
201 \begin_layout Plain Layout
202
203 https://yihui.org/knitr/demo/lyx/
204 \end_layout
205
206 \end_inset
207
208
209 \end_layout
210
211 \end_deeper
212 \begin_layout Itemize
213 If you use Sweave or
214 \series bold
215 knitr
216 \series default
217 with Beamer in LyX, you must use the
218 \emph on
219 FragileFrame
220 \emph default
221 environment for the frames that contain R code chunks.
222 Let's see if
223 \series bold
224 knitr
225 \series default
226 works with Beamer in this small demo.
227
228 \end_layout
229
230 \end_deeper
231 \begin_layout Section
232 First Test
233 \end_layout
234
235 \begin_layout FragileFrame
236 \begin_inset Argument 4
237 status open
238
239 \begin_layout Plain Layout
240 First Test
241 \end_layout
242
243 \end_inset
244
245
246 \end_layout
247
248 \begin_deeper
249 \begin_layout Standard
250 OK, let's get started with just some text:
251 \end_layout
252
253 \begin_layout Standard
254 \begin_inset ERT
255 status open
256
257 \begin_layout Plain Layout
258
259 <<echo=FALSE,results='hide'>>=
260 \end_layout
261
262 \begin_layout Plain Layout
263
264 # some setup
265 \end_layout
266
267 \begin_layout Plain Layout
268
269 options(width=60) # make the printing fit on the page
270 \end_layout
271
272 \begin_layout Plain Layout
273
274 set.seed(1121) # make the results repeatable
275 \end_layout
276
277 \begin_layout Plain Layout
278
279 @
280 \end_layout
281
282 \begin_layout Plain Layout
283
284 \end_layout
285
286 \begin_layout Plain Layout
287
288 <<>>=
289 \end_layout
290
291 \begin_layout Plain Layout
292
293 # create some random numbers
294 \end_layout
295
296 \begin_layout Plain Layout
297
298 (x=rnorm(20))
299 \end_layout
300
301 \begin_layout Plain Layout
302
303 mean(x);var(x)
304 \end_layout
305
306 \begin_layout Plain Layout
307
308 @
309 \end_layout
310
311 \end_inset
312
313
314 \end_layout
315
316 \begin_layout Standard
317 BTW, the first element of
318 \family typewriter
319 x
320 \family default
321 is
322 \begin_inset ERT
323 status open
324
325 \begin_layout Plain Layout
326
327
328 \backslash
329 Sexpr{x[1]}
330 \end_layout
331
332 \end_inset
333
334 .
335 (Did you notice the use of
336 \family typewriter
337
338 \backslash
339 Sexpr{}
340 \family default
341 ?)
342 \end_layout
343
344 \end_deeper
345 \begin_layout Section
346 Second Test
347 \end_layout
348
349 \begin_layout FragileFrame
350 \begin_inset Argument 4
351 status open
352
353 \begin_layout Plain Layout
354 Second Test
355 \end_layout
356
357 \end_inset
358
359
360 \end_layout
361
362 \begin_deeper
363 \begin_layout Standard
364 Text is nice but let's see what happens if we make a couple of plots in
365 our chunk:
366 \end_layout
367
368 \begin_layout Standard
369 \begin_inset ERT
370 status open
371
372 \begin_layout Plain Layout
373
374 <<boring-plots,fig.width=4,fig.height=4,out.width='.45
375 \backslash
376
377 \backslash
378 linewidth'>>=
379 \end_layout
380
381 \begin_layout Plain Layout
382
383 par(las=1,mar=c(4,4,.1,.1)) # tick labels direction
384 \end_layout
385
386 \begin_layout Plain Layout
387
388 boxplot(x)
389 \end_layout
390
391 \begin_layout Plain Layout
392
393 hist(x,main='',col="blue",probability=TRUE)
394 \end_layout
395
396 \begin_layout Plain Layout
397
398 lines(density(x),col="red")
399 \end_layout
400
401 \begin_layout Plain Layout
402
403 @
404 \end_layout
405
406 \end_inset
407
408
409 \end_layout
410
411 \end_deeper
412 \begin_layout Section
413 The Big Question
414 \end_layout
415
416 \begin_layout Frame
417 \begin_inset Argument 4
418 status open
419
420 \begin_layout Plain Layout
421 The Big Question
422 \end_layout
423
424 \end_inset
425
426
427 \end_layout
428
429 \begin_deeper
430 \begin_layout Standard
431 Do the above chunks work? You should be able to compile the LyX document
432 and get a nice-looking PDF slide presentation.
433 If not, time to double-check everything...
434 \end_layout
435
436 \end_deeper
437 \end_body
438 \end_document