]> git.lyx.org Git - lyx.git/blob - lib/examples/knitr.lyx
When a counter is stepped, reset recursively all slaves
[lyx.git] / lib / examples / knitr.lyx
1 #LyX 2.2 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 false
73 \output_changes false
74 \html_math_output 0
75 \html_css_as_file 0
76 \html_be_strict false
77 \end_header
78
79 \begin_body
80
81 \begin_layout Title
82 Using knitr with \SpecialChar LyX
83
84 \end_layout
85
86 \begin_layout Author
87 Yihui Xie
88 \begin_inset Foot
89 status collapsed
90
91 \begin_layout Plain Layout
92 Department of Statistics, Iowa State University.
93  Email: 
94 \begin_inset CommandInset href
95 LatexCommand href
96 name "xie@yihui.name"
97 target "xie@yihui.name"
98 type "mailto:"
99
100 \end_inset
101
102
103 \end_layout
104
105 \end_inset
106
107
108 \end_layout
109
110 \begin_layout Standard
111 The R (
112 \begin_inset Flex URL
113 status collapsed
114
115 \begin_layout Plain Layout
116
117 http://www.r-project.org
118 \end_layout
119
120 \end_inset
121
122 ) package 
123 \series bold
124 knitr
125 \series default
126  is an alternative tool to Sweave based on a different design with more
127  features.
128  \SpecialChar LyX
129  has native support to Sweave since version 2.0.0, and the support to 
130 \series bold
131 knitr
132 \series default
133  was also added since 2.0.3.
134  The usage is basically the same as the 
135 \family sans
136 Sweave
137 \family default
138  module
139 \begin_inset Foot
140 status open
141
142 \begin_layout Plain Layout
143 read the \SpecialChar LyX
144 /Sweave manual from 
145 \family sans
146 Help\SpecialChar menuseparator
147 Specific Manuals
148 \end_layout
149
150 \end_inset
151
152 :
153 \end_layout
154
155 \begin_layout Enumerate
156 Open a new \SpecialChar LyX
157  document;
158 \end_layout
159
160 \begin_layout Enumerate
161 Go to 
162 \family sans
163 Document\SpecialChar menuseparator
164 Settings\SpecialChar menuseparator
165 Modules
166 \family default
167  and insert the module named 
168 \family sans
169 Rnw (knitr)
170 \family default
171 ;
172 \end_layout
173
174 \begin_layout Enumerate
175 Then insert R code in the document with either 
176 \family sans
177 Insert\SpecialChar menuseparator
178 \SpecialChar TeX
179  Code
180 \family default
181  or the 
182 \family sans
183 Chunk
184 \family default
185  environment;
186 \end_layout
187
188 \begin_layout Standard
189 The package website 
190 \begin_inset Flex URL
191 status collapsed
192
193 \begin_layout Plain Layout
194
195 http://yihui.name/knitr
196 \end_layout
197
198 \end_inset
199
200  has full documentation and demos of 
201 \series bold
202 knitr
203 \series default
204 ; many of the examples have links to the \SpecialChar LyX
205  source documents.
206 \end_layout
207
208 \begin_layout Standard
209 Note the 
210 \series bold
211 knitr
212 \series default
213  package requires R >= 2.14.1, so you need to update R if you are using an
214  old version of R.
215  Here we show one chunk as a simple example:
216 \end_layout
217
218 \begin_layout Standard
219 \begin_inset ERT
220 status open
221
222 \begin_layout Plain Layout
223
224 <<show-off>>=
225 \end_layout
226
227 \begin_layout Plain Layout
228
229 rnorm(5)
230 \end_layout
231
232 \begin_layout Plain Layout
233
234 df=data.frame(y=rnorm(100), x=1:100)
235 \end_layout
236
237 \begin_layout Plain Layout
238
239 summary(lm(y~x, data=df))
240 \end_layout
241
242 \begin_layout Plain Layout
243
244 @
245 \end_layout
246
247 \end_inset
248
249
250 \end_layout
251
252 \begin_layout Standard
253 Please contact the package author in case of any problems.
254 \end_layout
255
256 \end_body
257 \end_document