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