]> git.lyx.org Git - lyx.git/blob - lib/examples/knitr.lyx
Update Sweave, Knitr manual and showcase the new Navigate menu
[lyx.git] / lib / examples / knitr.lyx
1 #LyX 2.3 created this file. For more info see http://www.lyx.org/
2 \lyxformat 508
3 \begin_document
4 \begin_header
5 \save_transient_properties true
6 \origin /systemlyxdir/examples/
7 \textclass article
8 \use_default_options true
9 \begin_modules
10 knitr
11 \end_modules
12 \maintain_unincluded_children false
13 \language english
14 \language_package default
15 \inputencoding auto
16 \fontencoding global
17 \font_roman "palatino" "default"
18 \font_sans "lmss" "default"
19 \font_typewriter "lmtt" "default"
20 \font_math "auto" "auto"
21 \font_default_family default
22 \use_non_tex_fonts false
23 \font_sc false
24 \font_osf false
25 \font_sf_scale 100 100
26 \font_tt_scale 100 100
27 \graphics default
28 \default_output_format default
29 \output_sync 0
30 \bibtex_command default
31 \index_command default
32 \paperfontsize default
33 \spacing single
34 \use_hyperref false
35 \papersize default
36 \use_geometry true
37 \use_package amsmath 1
38 \use_package amssymb 1
39 \use_package cancel 0
40 \use_package esint 1
41 \use_package mathdots 1
42 \use_package mathtools 0
43 \use_package mhchem 1
44 \use_package stackrel 0
45 \use_package stmaryrd 0
46 \use_package undertilde 1
47 \cite_engine basic
48 \cite_engine_type default
49 \biblio_style plain
50 \use_bibtopic false
51 \use_indices false
52 \paperorientation portrait
53 \suppress_date false
54 \justification true
55 \use_refstyle 1
56 \index Index
57 \shortcut idx
58 \color #008000
59 \end_index
60 \leftmargin 2.5cm
61 \topmargin 2.5cm
62 \rightmargin 2.5cm
63 \bottommargin 2.5cm
64 \secnumdepth 3
65 \tocdepth 3
66 \paragraph_separation indent
67 \paragraph_indentation default
68 \quotes_language english
69 \papercolumns 1
70 \papersides 1
71 \paperpagestyle default
72 \tracking_changes true
73 \output_changes false
74 \html_math_output 0
75 \html_css_as_file 0
76 \html_be_strict false
77 \author 2047637253 "Guillaume Munch"
78 \end_header
79
80 \begin_body
81
82 \begin_layout Title
83 Using knitr with \SpecialChar LyX
84
85 \end_layout
86
87 \begin_layout Author
88 Yihui Xie
89 \begin_inset Foot
90 status collapsed
91
92 \begin_layout Plain Layout
93 Department of Statistics, Iowa State University.
94  Email: 
95 \begin_inset CommandInset href
96 LatexCommand href
97 name "xie@yihui.name"
98 target "xie@yihui.name"
99 type "mailto:"
100
101 \end_inset
102
103
104 \end_layout
105
106 \end_inset
107
108
109 \end_layout
110
111 \begin_layout Standard
112 The R (
113 \begin_inset Flex URL
114 status collapsed
115
116 \begin_layout Plain Layout
117
118 http://www.r-project.org
119 \end_layout
120
121 \end_inset
122
123 ) package 
124 \series bold
125 knitr
126 \series default
127  is an alternative tool to Sweave based on a different design with more
128  features.
129  \SpecialChar LyX
130  has native support to Sweave since version 2.0.0, and the support to 
131 \series bold
132 knitr
133 \series default
134  was also added since 2.0.3.
135  The usage is basically the same as the 
136 \family sans
137 Sweave
138 \family default
139  module
140 \begin_inset Foot
141 status open
142
143 \begin_layout Plain Layout
144 read the \SpecialChar LyX
145 /Sweave manual from 
146 \family sans
147 Help\SpecialChar menuseparator
148 Specific Manuals
149 \end_layout
150
151 \end_inset
152
153 :
154 \end_layout
155
156 \begin_layout Enumerate
157 Open a new \SpecialChar LyX
158  document;
159 \end_layout
160
161 \begin_layout Enumerate
162 Go to 
163 \family sans
164 Document\SpecialChar menuseparator
165 Settings\SpecialChar menuseparator
166 Modules
167 \family default
168  and insert the module named 
169 \family sans
170 Rnw (knitr)
171 \family default
172 ;
173 \end_layout
174
175 \begin_layout Enumerate
176 Then insert R code in the document with either 
177 \family sans
178 Insert\SpecialChar menuseparator
179 \SpecialChar TeX
180  Code
181 \family default
182  or the 
183 \family sans
184 Chunk
185 \family default
186  environment;
187 \end_layout
188
189 \begin_layout Standard
190 The package website 
191 \begin_inset Flex URL
192 status collapsed
193
194 \begin_layout Plain Layout
195
196 http://yihui.name/knitr
197 \end_layout
198
199 \end_inset
200
201  has full documentation and demos of 
202 \series bold
203 knitr
204 \series default
205 ; many of the examples have links to the \SpecialChar LyX
206  source documents.
207 \change_inserted 2047637253 1483899260
208
209 \end_layout
210
211 \begin_layout Standard
212
213 \change_inserted 2047637253 1483899275
214 Since \SpecialChar LyX
215  2.3, it is necessary to enable the use of 
216 \emph on
217 needauth
218 \emph default
219  converters in
220 \family sans
221  Preferences\SpecialChar menuseparator
222 File Handling\SpecialChar menuseparator
223 Converters
224 \family default
225  in order to compile with 
226 \series bold
227 knitr
228 \series default
229 .
230 \change_unchanged
231
232 \end_layout
233
234 \begin_layout Standard
235 Note the 
236 \series bold
237 knitr
238 \series default
239  package requires R >= 2.14.1, so you need to update R if you are using an
240  old version of R.
241  Here we show one chunk as a simple example:
242 \end_layout
243
244 \begin_layout Standard
245
246 \change_inserted 2047637253 1483899195
247 \begin_inset Flex Chunk
248 status open
249
250 \begin_layout Plain Layout
251
252 \change_inserted 2047637253 1483899204
253
254 \begin_inset Argument 1
255 status open
256
257 \begin_layout Plain Layout
258
259 \change_inserted 2047637253 1483899200
260 show-off
261 \change_unchanged
262
263 \end_layout
264
265 \end_inset
266
267
268 \end_layout
269
270 \begin_layout Plain Layout
271
272 \change_inserted 2047637253 1483899204
273
274 rnorm(5)
275 \end_layout
276
277 \begin_layout Plain Layout
278
279 \change_inserted 2047637253 1483899204
280
281 df=data.frame(y=rnorm(100), x=1:100)
282 \end_layout
283
284 \begin_layout Plain Layout
285
286 \change_inserted 2047637253 1483899204
287
288 summary(lm(y~x, data=df))
289 \change_unchanged
290
291 \end_layout
292
293 \end_inset
294
295
296 \change_unchanged
297
298 \end_layout
299
300 \begin_layout Standard
301
302 \change_deleted 2047637253 1483899208
303 \begin_inset ERT
304 status open
305
306 \begin_layout Plain Layout
307
308 <<show-off>>=
309 \end_layout
310
311 \begin_layout Plain Layout
312
313 rnorm(5)
314 \end_layout
315
316 \begin_layout Plain Layout
317
318 df=data.frame(y=rnorm(100), x=1:100)
319 \end_layout
320
321 \begin_layout Plain Layout
322
323 summary(lm(y~x, data=df))
324 \end_layout
325
326 \begin_layout Plain Layout
327
328 @
329 \end_layout
330
331 \end_inset
332
333
334 \change_unchanged
335
336 \end_layout
337
338 \begin_layout Standard
339 Please contact the package author in case of any problems.
340 \end_layout
341
342 \end_body
343 \end_document