2017-01-08 18:19:55 +00:00
|
|
|
#LyX 2.3 created this file. For more info see http://www.lyx.org/
|
2016-04-06 03:43:44 +00:00
|
|
|
\lyxformat 508
|
2012-01-25 22:26:31 +00:00
|
|
|
\begin_document
|
|
|
|
\begin_header
|
2016-01-12 21:30:37 +00:00
|
|
|
\save_transient_properties true
|
2015-11-13 18:14:45 +00:00
|
|
|
\origin /systemlyxdir/examples/
|
2012-01-25 22:26:31 +00:00
|
|
|
\textclass article
|
|
|
|
\use_default_options true
|
|
|
|
\begin_modules
|
|
|
|
knitr
|
|
|
|
\end_modules
|
|
|
|
\maintain_unincluded_children false
|
|
|
|
\language english
|
|
|
|
\language_package default
|
|
|
|
\inputencoding auto
|
|
|
|
\fontencoding global
|
2015-11-13 18:14:45 +00:00
|
|
|
\font_roman "palatino" "default"
|
|
|
|
\font_sans "lmss" "default"
|
|
|
|
\font_typewriter "lmtt" "default"
|
|
|
|
\font_math "auto" "auto"
|
2012-01-25 22:26:31 +00:00
|
|
|
\font_default_family default
|
|
|
|
\use_non_tex_fonts false
|
|
|
|
\font_sc false
|
|
|
|
\font_osf false
|
2015-11-13 18:14:45 +00:00
|
|
|
\font_sf_scale 100 100
|
|
|
|
\font_tt_scale 100 100
|
2012-01-25 22:26:31 +00:00
|
|
|
\graphics default
|
|
|
|
\default_output_format default
|
|
|
|
\output_sync 0
|
|
|
|
\bibtex_command default
|
|
|
|
\index_command default
|
|
|
|
\paperfontsize default
|
|
|
|
\spacing single
|
|
|
|
\use_hyperref false
|
|
|
|
\papersize default
|
|
|
|
\use_geometry true
|
|
|
|
\use_package amsmath 1
|
2014-03-23 16:31:51 +00:00
|
|
|
\use_package amssymb 1
|
|
|
|
\use_package cancel 0
|
2012-01-25 22:26:31 +00:00
|
|
|
\use_package esint 1
|
|
|
|
\use_package mathdots 1
|
|
|
|
\use_package mathtools 0
|
|
|
|
\use_package mhchem 1
|
2014-03-23 16:31:51 +00:00
|
|
|
\use_package stackrel 0
|
|
|
|
\use_package stmaryrd 0
|
2012-01-25 22:26:31 +00:00
|
|
|
\use_package undertilde 1
|
|
|
|
\cite_engine basic
|
2014-03-23 16:31:51 +00:00
|
|
|
\cite_engine_type default
|
2012-01-25 22:26:31 +00:00
|
|
|
\biblio_style plain
|
|
|
|
\use_bibtopic false
|
|
|
|
\use_indices false
|
|
|
|
\paperorientation portrait
|
|
|
|
\suppress_date false
|
|
|
|
\justification true
|
|
|
|
\use_refstyle 1
|
|
|
|
\index Index
|
|
|
|
\shortcut idx
|
|
|
|
\color #008000
|
|
|
|
\end_index
|
|
|
|
\leftmargin 2.5cm
|
|
|
|
\topmargin 2.5cm
|
|
|
|
\rightmargin 2.5cm
|
|
|
|
\bottommargin 2.5cm
|
|
|
|
\secnumdepth 3
|
|
|
|
\tocdepth 3
|
|
|
|
\paragraph_separation indent
|
|
|
|
\paragraph_indentation default
|
|
|
|
\quotes_language english
|
|
|
|
\papercolumns 1
|
|
|
|
\papersides 1
|
|
|
|
\paperpagestyle default
|
2017-01-08 18:19:55 +00:00
|
|
|
\tracking_changes true
|
2012-01-25 22:26:31 +00:00
|
|
|
\output_changes false
|
|
|
|
\html_math_output 0
|
|
|
|
\html_css_as_file 0
|
|
|
|
\html_be_strict false
|
2017-01-08 18:19:55 +00:00
|
|
|
\author 2047637253 "Guillaume Munch"
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_header
|
|
|
|
|
|
|
|
\begin_body
|
|
|
|
|
|
|
|
\begin_layout Title
|
2016-01-13 01:51:42 +00:00
|
|
|
Using knitr with \SpecialChar LyX
|
|
|
|
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Author
|
|
|
|
Yihui Xie
|
|
|
|
\begin_inset Foot
|
|
|
|
status collapsed
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
Department of Statistics, Iowa State University.
|
|
|
|
Email:
|
|
|
|
\begin_inset CommandInset href
|
|
|
|
LatexCommand href
|
|
|
|
name "xie@yihui.name"
|
|
|
|
target "xie@yihui.name"
|
|
|
|
type "mailto:"
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
The R (
|
|
|
|
\begin_inset Flex URL
|
|
|
|
status collapsed
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
http://www.r-project.org
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
) package
|
|
|
|
\series bold
|
|
|
|
knitr
|
|
|
|
\series default
|
|
|
|
is an alternative tool to Sweave based on a different design with more
|
|
|
|
features.
|
2016-01-13 01:51:42 +00:00
|
|
|
\SpecialChar LyX
|
|
|
|
has native support to Sweave since version 2.0.0, and the support to
|
2012-01-25 22:26:31 +00:00
|
|
|
\series bold
|
|
|
|
knitr
|
|
|
|
\series default
|
|
|
|
was also added since 2.0.3.
|
|
|
|
The usage is basically the same as the
|
|
|
|
\family sans
|
|
|
|
Sweave
|
|
|
|
\family default
|
|
|
|
module
|
|
|
|
\begin_inset Foot
|
|
|
|
status open
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
2016-01-13 01:51:42 +00:00
|
|
|
read the \SpecialChar LyX
|
2015-11-13 18:14:45 +00:00
|
|
|
/Sweave manual from
|
2012-01-25 22:26:31 +00:00
|
|
|
\family sans
|
2015-11-13 18:14:45 +00:00
|
|
|
Help\SpecialChar menuseparator
|
2012-01-25 22:26:31 +00:00
|
|
|
Specific Manuals
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
:
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Enumerate
|
2016-01-13 01:51:42 +00:00
|
|
|
Open a new \SpecialChar LyX
|
2015-11-13 18:14:45 +00:00
|
|
|
document;
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Enumerate
|
|
|
|
Go to
|
|
|
|
\family sans
|
2015-11-13 18:14:45 +00:00
|
|
|
Document\SpecialChar menuseparator
|
|
|
|
Settings\SpecialChar menuseparator
|
2012-01-25 22:26:31 +00:00
|
|
|
Modules
|
|
|
|
\family default
|
|
|
|
and insert the module named
|
|
|
|
\family sans
|
|
|
|
Rnw (knitr)
|
|
|
|
\family default
|
|
|
|
;
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Enumerate
|
|
|
|
Then insert R code in the document with either
|
|
|
|
\family sans
|
2015-11-13 18:14:45 +00:00
|
|
|
Insert\SpecialChar menuseparator
|
2016-01-13 01:51:42 +00:00
|
|
|
\SpecialChar TeX
|
2015-11-13 18:14:45 +00:00
|
|
|
Code
|
2012-01-25 22:26:31 +00:00
|
|
|
\family default
|
|
|
|
or the
|
|
|
|
\family sans
|
|
|
|
Chunk
|
|
|
|
\family default
|
|
|
|
environment;
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
The package website
|
|
|
|
\begin_inset Flex URL
|
|
|
|
status collapsed
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
2012-10-07 01:01:34 +00:00
|
|
|
http://yihui.name/knitr
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
has full documentation and demos of
|
|
|
|
\series bold
|
|
|
|
knitr
|
|
|
|
\series default
|
2016-01-13 01:51:42 +00:00
|
|
|
; many of the examples have links to the \SpecialChar LyX
|
2015-11-13 18:14:45 +00:00
|
|
|
source documents.
|
2017-01-08 18:19:55 +00:00
|
|
|
\change_inserted 2047637253 1483899260
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899275
|
|
|
|
Since \SpecialChar LyX
|
|
|
|
2.3, it is necessary to enable the use of
|
|
|
|
\emph on
|
|
|
|
needauth
|
|
|
|
\emph default
|
|
|
|
converters in
|
|
|
|
\family sans
|
|
|
|
Preferences\SpecialChar menuseparator
|
|
|
|
File Handling\SpecialChar menuseparator
|
|
|
|
Converters
|
|
|
|
\family default
|
|
|
|
in order to compile with
|
|
|
|
\series bold
|
|
|
|
knitr
|
|
|
|
\series default
|
|
|
|
.
|
|
|
|
\change_unchanged
|
|
|
|
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
Note the
|
|
|
|
\series bold
|
|
|
|
knitr
|
|
|
|
\series default
|
|
|
|
package requires R >= 2.14.1, so you need to update R if you are using an
|
|
|
|
old version of R.
|
|
|
|
Here we show one chunk as a simple example:
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
2017-01-08 18:19:55 +00:00
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899195
|
|
|
|
\begin_inset Flex Chunk
|
|
|
|
status open
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899204
|
|
|
|
|
|
|
|
\begin_inset Argument 1
|
|
|
|
status open
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899200
|
|
|
|
show-off
|
|
|
|
\change_unchanged
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899204
|
|
|
|
|
|
|
|
rnorm(5)
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899204
|
|
|
|
|
|
|
|
df=data.frame(y=rnorm(100), x=1:100)
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
\change_inserted 2047637253 1483899204
|
|
|
|
|
|
|
|
summary(lm(y~x, data=df))
|
|
|
|
\change_unchanged
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
|
|
|
|
\change_unchanged
|
|
|
|
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
|
|
|
|
\change_deleted 2047637253 1483899208
|
2012-01-25 22:26:31 +00:00
|
|
|
\begin_inset ERT
|
|
|
|
status open
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
<<show-off>>=
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
rnorm(5)
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
df=data.frame(y=rnorm(100), x=1:100)
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
summary(lm(y~x, data=df))
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
|
|
|
|
@
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_inset
|
|
|
|
|
|
|
|
|
2017-01-08 18:19:55 +00:00
|
|
|
\change_unchanged
|
|
|
|
|
2012-01-25 22:26:31 +00:00
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\begin_layout Standard
|
|
|
|
Please contact the package author in case of any problems.
|
|
|
|
\end_layout
|
|
|
|
|
|
|
|
\end_body
|
|
|
|
\end_document
|