]> git.lyx.org Git - lyx.git/blob - lib/examples/Modules/Rnw_%28knitr%29.lyx
Amend 357bc257, Typo: correct reference of script
[lyx.git] / lib / examples / Modules / Rnw_%28knitr%29.lyx
1 #LyX 2.4 created this file. For more info see https://www.lyx.org/
2 \lyxformat 600
3 \begin_document
4 \begin_header
5 \save_transient_properties true
6 \origin /systemlyxdir/examples/Modules/
7 \textclass article
8 \use_default_options true
9 \begin_modules
10 knitr
11 \end_modules
12 \maintain_unincluded_children no
13 \language english
14 \language_package default
15 \inputencoding utf8
16 \fontencoding auto
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_sans_osf false
25 \font_typewriter_osf false
26 \font_roman_osf false
27 \font_sf_scale 100 100
28 \font_tt_scale 100 100
29 \use_microtype false
30 \use_dash_ligatures false
31 \graphics default
32 \default_output_format default
33 \output_sync 0
34 \bibtex_command default
35 \index_command default
36 \paperfontsize default
37 \spacing single
38 \use_hyperref false
39 \papersize default
40 \use_geometry true
41 \use_package amsmath 1
42 \use_package amssymb 1
43 \use_package cancel 1
44 \use_package esint 1
45 \use_package mathdots 1
46 \use_package mathtools 1
47 \use_package mhchem 1
48 \use_package stackrel 1
49 \use_package stmaryrd 1
50 \use_package undertilde 1
51 \cite_engine basic
52 \cite_engine_type default
53 \biblio_style plain
54 \use_bibtopic false
55 \use_indices false
56 \paperorientation portrait
57 \suppress_date false
58 \justification true
59 \use_refstyle 1
60 \use_minted 0
61 \use_lineno 0
62 \index Index
63 \shortcut idx
64 \color #008000
65 \end_index
66 \leftmargin 2.5cm
67 \topmargin 2.5cm
68 \rightmargin 2.5cm
69 \bottommargin 2.5cm
70 \secnumdepth 3
71 \tocdepth 3
72 \paragraph_separation indent
73 \paragraph_indentation default
74 \is_math_indent 0
75 \math_numbering_side default
76 \quotes_style english
77 \dynamic_quotes 0
78 \papercolumns 1
79 \papersides 1
80 \paperpagestyle default
81 \tracking_changes false
82 \postpone_fragile_content false
83 \output_changes false
84 \html_math_output 0
85 \html_css_as_file 0
86 \html_be_strict false
87 \end_header
88
89 \begin_body
90
91 \begin_layout Title
92 Using knitr with \SpecialChar LyX
93
94 \end_layout
95
96 \begin_layout Author
97 Yihui Xie
98 \begin_inset Foot
99 status collapsed
100
101 \begin_layout Plain Layout
102 Department of Statistics, Iowa State University.
103  Email: 
104 \begin_inset CommandInset href
105 LatexCommand href
106 name "xie@yihui.name"
107 target "xie@yihui.name"
108 type "mailto:"
109 literal "false"
110
111 \end_inset
112
113
114 \end_layout
115
116 \end_inset
117
118
119 \end_layout
120
121 \begin_layout Standard
122 The R (
123 \begin_inset Flex URL
124 status collapsed
125
126 \begin_layout Plain Layout
127
128 http://www.r-project.org
129 \end_layout
130
131 \end_inset
132
133 ) package 
134 \series bold
135 knitr
136 \series default
137  is an alternative tool to Sweave based on a different design with more
138  features.
139  \SpecialChar LyX
140  has native support to Sweave since version 2.0.0, and the support to 
141 \series bold
142 knitr
143 \series default
144  was also added since 2.0.3.
145  The usage is basically the same as the 
146 \family sans
147 Sweave
148 \family default
149  module
150 \begin_inset Foot
151 status open
152
153 \begin_layout Plain Layout
154 read the \SpecialChar LyX
155 /Sweave manual from 
156 \family sans
157 Help\SpecialChar menuseparator
158 Specific Manuals
159 \end_layout
160
161 \end_inset
162
163 :
164 \end_layout
165
166 \begin_layout Enumerate
167 Open a new \SpecialChar LyX
168  document;
169 \end_layout
170
171 \begin_layout Enumerate
172 Go to 
173 \family sans
174 Document\SpecialChar menuseparator
175 Settings\SpecialChar menuseparator
176 Modules
177 \family default
178  and insert the module named 
179 \family sans
180 Rnw (knitr)
181 \family default
182 ;
183 \end_layout
184
185 \begin_layout Enumerate
186 Then insert R code in the document with either 
187 \family sans
188 Insert\SpecialChar menuseparator
189 \SpecialChar TeX
190  Code
191 \family default
192  or the 
193 \family sans
194 Chunk
195 \family default
196  environment;
197 \end_layout
198
199 \begin_layout Standard
200 The package website 
201 \begin_inset Flex URL
202 status collapsed
203
204 \begin_layout Plain Layout
205
206 http://yihui.name/knitr
207 \end_layout
208
209 \end_inset
210
211  has full documentation and demos of 
212 \series bold
213 knitr
214 \series default
215 ; many of the examples have links to the \SpecialChar LyX
216  source documents.
217 \end_layout
218
219 \begin_layout Standard
220 Since \SpecialChar LyX
221  2.3, it is necessary to enable the use of 
222 \emph on
223 needauth
224 \emph default
225  converters in
226 \family sans
227  Preferences\SpecialChar menuseparator
228 File Handling\SpecialChar menuseparator
229 Converters
230 \family default
231  in order to compile with 
232 \series bold
233 knitr
234 \series default
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 \begin_inset Flex Chunk
250 status open
251
252 \begin_layout Plain Layout
253
254 \begin_inset Argument 1
255 status open
256
257 \begin_layout Plain Layout
258
259 show-off
260 \end_layout
261
262 \end_inset
263
264
265 \end_layout
266
267 \begin_layout Plain Layout
268
269 rnorm(5)
270 \end_layout
271
272 \begin_layout Plain Layout
273
274 df=data.frame(y=rnorm(100), x=1:100)
275 \end_layout
276
277 \begin_layout Plain Layout
278
279 summary(lm(y~x, data=df))
280 \end_layout
281
282 \end_inset
283
284
285 \end_layout
286
287 \begin_layout Standard
288 Please contact the package author in case of any problems.
289 \end_layout
290
291 \end_body
292 \end_document