]> git.lyx.org Git - lyx.git/blob - lib/examples/knitr.lyx
powerdot.layout: use the default floats
[lyx.git] / lib / examples / knitr.lyx
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 article
6 \use_default_options true
7 \begin_modules
8 knitr
9 \end_modules
10 \maintain_unincluded_children false
11 \language english
12 \language_package default
13 \inputencoding auto
14 \fontencoding global
15 \font_roman palatino
16 \font_sans lmss
17 \font_typewriter lmtt
18 \font_math auto
19 \font_default_family default
20 \use_non_tex_fonts false
21 \font_sc false
22 \font_osf false
23 \font_sf_scale 100
24 \font_tt_scale 100
25 \graphics default
26 \default_output_format default
27 \output_sync 0
28 \bibtex_command default
29 \index_command default
30 \paperfontsize default
31 \spacing single
32 \use_hyperref false
33 \papersize default
34 \use_geometry true
35 \use_package amsmath 1
36 \use_package amssymb 1
37 \use_package cancel 0
38 \use_package esint 1
39 \use_package mathdots 1
40 \use_package mathtools 0
41 \use_package mhchem 1
42 \use_package stackrel 0
43 \use_package stmaryrd 0
44 \use_package undertilde 1
45 \cite_engine basic
46 \cite_engine_type default
47 \biblio_style plain
48 \use_bibtopic false
49 \use_indices false
50 \paperorientation portrait
51 \suppress_date false
52 \justification true
53 \use_refstyle 1
54 \index Index
55 \shortcut idx
56 \color #008000
57 \end_index
58 \leftmargin 2.5cm
59 \topmargin 2.5cm
60 \rightmargin 2.5cm
61 \bottommargin 2.5cm
62 \secnumdepth 3
63 \tocdepth 3
64 \paragraph_separation indent
65 \paragraph_indentation default
66 \quotes_language english
67 \papercolumns 1
68 \papersides 1
69 \paperpagestyle default
70 \tracking_changes false
71 \output_changes false
72 \html_math_output 0
73 \html_css_as_file 0
74 \html_be_strict false
75 \end_header
76
77 \begin_body
78
79 \begin_layout Title
80 Using knitr with LyX
81 \end_layout
82
83 \begin_layout Author
84 Yihui Xie
85 \begin_inset Foot
86 status collapsed
87
88 \begin_layout Plain Layout
89 Department of Statistics, Iowa State University.
90  Email: 
91 \begin_inset CommandInset href
92 LatexCommand href
93 name "xie@yihui.name"
94 target "xie@yihui.name"
95 type "mailto:"
96
97 \end_inset
98
99
100 \end_layout
101
102 \end_inset
103
104
105 \end_layout
106
107 \begin_layout Standard
108 The R (
109 \begin_inset Flex URL
110 status collapsed
111
112 \begin_layout Plain Layout
113
114 http://www.r-project.org
115 \end_layout
116
117 \end_inset
118
119 ) package 
120 \series bold
121 knitr
122 \series default
123  is an alternative tool to Sweave based on a different design with more
124  features.
125  LyX has native support to Sweave since version 2.0.0, and the support to
126  
127 \series bold
128 knitr
129 \series default
130  was also added since 2.0.3.
131  The usage is basically the same as the 
132 \family sans
133 Sweave
134 \family default
135  module
136 \begin_inset Foot
137 status open
138
139 \begin_layout Plain Layout
140 read the LyX/Sweave manual from 
141 \family sans
142 Help\SpecialChar \menuseparator
143 Specific Manuals
144 \end_layout
145
146 \end_inset
147
148 :
149 \end_layout
150
151 \begin_layout Enumerate
152 Open a new LyX document;
153 \end_layout
154
155 \begin_layout Enumerate
156 Go to 
157 \family sans
158 Document\SpecialChar \menuseparator
159 Settings\SpecialChar \menuseparator
160 Modules
161 \family default
162  and insert the module named 
163 \family sans
164 Rnw (knitr)
165 \family default
166 ;
167 \end_layout
168
169 \begin_layout Enumerate
170 Then insert R code in the document with either 
171 \family sans
172 Insert\SpecialChar \menuseparator
173 TeX Code
174 \family default
175  or the 
176 \family sans
177 Chunk
178 \family default
179  environment;
180 \end_layout
181
182 \begin_layout Standard
183 The package website 
184 \begin_inset Flex URL
185 status collapsed
186
187 \begin_layout Plain Layout
188
189 http://yihui.name/knitr
190 \end_layout
191
192 \end_inset
193
194  has full documentation and demos of 
195 \series bold
196 knitr
197 \series default
198 ; many of the examples have links to the LyX source documents.
199 \end_layout
200
201 \begin_layout Standard
202 Note the 
203 \series bold
204 knitr
205 \series default
206  package requires R >= 2.14.1, so you need to update R if you are using an
207  old version of R.
208  Here we show one chunk as a simple example:
209 \end_layout
210
211 \begin_layout Standard
212 \begin_inset ERT
213 status open
214
215 \begin_layout Plain Layout
216
217 <<show-off>>=
218 \end_layout
219
220 \begin_layout Plain Layout
221
222 rnorm(5)
223 \end_layout
224
225 \begin_layout Plain Layout
226
227 df=data.frame(y=rnorm(100), x=1:100)
228 \end_layout
229
230 \begin_layout Plain Layout
231
232 summary(lm(y~x, data=df))
233 \end_layout
234
235 \begin_layout Plain Layout
236
237 @
238 \end_layout
239
240 \end_inset
241
242
243 \end_layout
244
245 \begin_layout Standard
246 Please contact the package author in case of any problems.
247 \end_layout
248
249 \end_body
250 \end_document