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