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