-#LyX 2.0 created this file. For more info see http://www.lyx.org/
-\lyxformat 413
+#LyX 2.2 created this file. For more info see http://www.lyx.org/
+\lyxformat 503
\begin_document
\begin_header
+\origin /systemlyxdir/examples/
\textclass article
\begin_preamble
%% maxwidth is the original width if it's less than linewidth
\language_package auto
\inputencoding default
\fontencoding global
-\font_roman palatino
-\font_sans lmss
-\font_typewriter lmtt
+\font_roman "palatino" "default"
+\font_sans "lmss" "default"
+\font_typewriter "lmtt" "default"
+\font_math "auto" "auto"
\font_default_family default
\use_non_tex_fonts false
\font_sc false
\font_osf false
-\font_sf_scale 100
-\font_tt_scale 100
-
+\font_sf_scale 100 100
+\font_tt_scale 100 100
\graphics default
\default_output_format default
\output_sync 0
\use_hyperref false
\papersize default
\use_geometry true
-\use_amsmath 1
-\use_esint 1
-\use_mhchem 1
-\use_mathdots 1
+\use_package amsmath 1
+\use_package amssymb 1
+\use_package cancel 0
+\use_package esint 1
+\use_package mathdots 1
+\use_package mathtools 0
+\use_package mhchem 1
+\use_package stackrel 0
+\use_package stmaryrd 0
+\use_package undertilde 0
\cite_engine basic
+\cite_engine_type default
+\biblio_style plain
\use_bibtopic false
\use_indices false
\paperorientation portrait
\suppress_date false
+\justification true
\use_refstyle 0
\index Index
\shortcut idx
\end_layout
\begin_layout Title
-Using Sweave with LyX
+Using Sweave with \SpecialCharNoPassThru LyX
\end_layout
\begin_layout Author
\end_inset
) for dynamic report generation using the ideas of literate programming.
- R code can be mixed into a LaTeX document, and will be executed in R when
- the document is compiled; the results are written into the TeX output.
+ R code can be mixed into a \SpecialCharNoPassThru LaTeX
+ document, and will be executed in R when
+ the document is compiled; the results are written into the \SpecialCharNoPassThru TeX
+ output.
\end_layout
\begin_layout Standard
-Since LyX 2.0, Sweave can be used out of the box with any document class
+Since \SpecialCharNoPassThru LyX
+ 2.0, Sweave can be used out of the box with any document class
using the
\family sans
Sweave
\family default
- module, which means we no longer need to modify the
-\family sans
-preferences
-\family default
- file manually or add special layouts such as
-\family sans
-literate-article.layout
-\family default
- and
-\family sans
-literate-book.layout
-\family default
- like we did before.
+ module.
We can add the
\family sans
Sweave
\family default
- module to a LyX document from
+ module to a \SpecialCharNoPassThru LyX
+ document from
\family sans
-Document\SpecialChar \menuseparator
-Settings\SpecialChar \menuseparator
+Document\SpecialChar menuseparator
+Settings\SpecialChar menuseparator
Modules
\family default
.
\family default
anyway), or go to
\family sans
-Tools\SpecialChar \menuseparator
-Preferences\SpecialChar \menuseparator
-Paths\SpecialChar \menuseparator
+Tools\SpecialChar menuseparator
+Preferences\SpecialChar menuseparator
+Paths\SpecialChar menuseparator
PATH prefix
\family default
to add the bin path of R (recommended), which is often like
\end_layout
\begin_layout Standard
-After you have done these changes, you need to reconfigure LyX by
+After you have done these changes, you need to reconfigure \SpecialCharNoPassThru LyX
+ by
\family sans
-Tools\SpecialChar \menuseparator
+Tools\SpecialChar menuseparator
Reconfigure
\family default
.
module will be unavailable.
It is recommended to use the latest version of R, since Sweave is still
being updated.
- Another dependency is introduced by the LaTeX style file
+ Another dependency is introduced by the \SpecialCharNoPassThru LaTeX
+ style file
\family sans
Sweave.sty
\family default
\end_layout
\begin_layout Standard
-MikTeX users may add the texmf directory to the list of root directories
- in MikTeX through MikTeX settings.
+Mik\SpecialCharNoPassThru TeX
+ users may add the texmf directory to the list of root directories
+ in Mik\SpecialCharNoPassThru TeX
+ through Mik\SpecialCharNoPassThru TeX
+ settings.
Further note that
\family sans
Sweave.sty
ae
\series default
.
- If LyX cannot find
+ If \SpecialCharNoPassThru LyX
+ cannot find
\family sans
Sweave.sty
\family default
\backslash
SweaveOpts{}
\family default
- in Sweave and it can be inserted in a LyX document by
+ in Sweave and it can be inserted in a \SpecialCharNoPassThru LyX
+ document by
\family sans
-Insert\SpecialChar \menuseparator
-Custom Insets\SpecialChar \menuseparator
+Insert\SpecialChar menuseparator
+Custom Insets\SpecialChar menuseparator
Sweave Options
\family default
-, or just use TeX code to write it (
+, or just use \SpecialCharNoPassThru TeX
+ code to write it (
\family sans
-Insert\SpecialChar \menuseparator
-TeX Code
+Insert\SpecialChar menuseparator
+\SpecialCharNoPassThru TeX
+ Code
\family default
).
For example, we can set a global option
echo=FALSE
\family default
in the beginning of a document to suppress all R code (by default, both
- R code and its output will show up in the LaTeX document).
+ R code and its output will show up in the \SpecialCharNoPassThru LaTeX
+ document).
\end_layout
\begin_layout Standard
-To write R code in LyX, you can first switch to the
+To write R code in \SpecialCharNoPassThru LyX
+, you can first switch to the
\family typewriter
Chunk
\family default
environment in the layout styles list (droplist in the top-left corner
- in the toolbar), or you can simply open a TeX code environment and write
+ in the toolbar), or you can simply open a \SpecialCharNoPassThru TeX
+ code environment and write
Sweave code chunks in it.
The latter approach is recommended since it is more stable.
\end_layout
\backslash
Sexpr{}
\family default
-, and the corresponding LyX menu is
+, and the corresponding \SpecialCharNoPassThru LyX
+ menu is
\family sans
-Insert\SpecialChar \menuseparator
-Custom Insets\SpecialChar \menuseparator
+Insert\SpecialChar menuseparator
+Custom Insets\SpecialChar menuseparator
S/R expression
\family default
-, or alternatively just use TeX code.
+, or alternatively just use \SpecialCharNoPassThru TeX
+ code.
For example, the third element of the vector
\family typewriter
x
status open
\begin_layout Plain Layout
-\begin_inset Caption
+\begin_inset Caption Standard
\begin_layout Plain Layout
Quantiles of the first four variables in the
\family typewriter
results=tex
\family default
- makes sure that the R output is written out as raw LaTeX code instead of
+ makes sure that the R output is written out as raw \SpecialCharNoPassThru LaTeX
+ code instead of
being wrapped in a special environment (
\family typewriter
Soutput
\begin_layout Plain Layout
\align center
+\begin_inset Note Note
+status open
+
+\begin_layout Plain Layout
+Both eps and pdf are set to true so that both latex and pdflatex work.
+ In practice, you would probably just choose one.
+\end_layout
+
+\end_inset
+
+
\begin_inset ERT
status open
\begin_layout Plain Layout
-<<iris-pairs,fig=TRUE,width=4.5,height=4.5>>=
+<<iris-pairs,fig=TRUE,width=4.5,height=4.5,eps=TRUE,pdf=TRUE>>=
\end_layout
\begin_layout Plain Layout
\end_layout
\begin_layout Plain Layout
-\begin_inset Caption
+\begin_inset Caption Standard
\begin_layout Plain Layout
Scatter plot matrix of the
\begin_layout Plain Layout
-<<iris-boxplots,fig=TRUE,width=7,height=2,keep.source=F>>=
+<<iris-boxplots,fig=TRUE,width=7,height=2,keep.source=F,eps=T,pdf=T>>=
\end_layout
\begin_layout Plain Layout
\end_layout
\begin_layout Plain Layout
-\begin_inset Caption
+\begin_inset Caption Standard
\begin_layout Plain Layout
Boxplots of sepal length grouped by species.
We can also export all the R code in an Sweave document as a single R script
(
\family sans
-File\SpecialChar \menuseparator
-Export\SpecialChar \menuseparator
+File\SpecialChar menuseparator
+Export\SpecialChar menuseparator
R/S code
\family default
), which is done via
\family sans
Sweave
\family default
- module declares that a LyX document contains literate programming components
- with R, so that LyX will handle such documents according to the specific
+ module declares that a \SpecialCharNoPassThru LyX
+ document contains literate programming components
+ with R, so that \SpecialCharNoPassThru LyX
+ will handle such documents according to the specific
converters (see the Customization manual).
The
\family sans
\family sans
scripts
\family default
- directory of LyX.
+ directory of \SpecialCharNoPassThru LyX
+.
This script takes an
\family sans
Rnw
\family default
- document from LyX and call Sweave to process it to a TeX document, then
- LyX takes care of the rest of work.
+ document from \SpecialCharNoPassThru LyX
+ and call Sweave to process it to a \SpecialCharNoPassThru TeX
+ document, then
+ \SpecialCharNoPassThru LyX
+ takes care of the rest of work.
\end_layout
\begin_layout Standard
\family sans
sweave
\family default
- format to LaTeX is a call to R via the command line as:
+ format to \SpecialCharNoPassThru LaTeX
+ is a call to R via the command line as:
\end_layout
\begin_layout Standard
\end_layout
\begin_layout Standard
-The LyX library directory
+The \SpecialCharNoPassThru LyX
+ library directory
\family typewriter
$$s
\family default
can be found from the menu
\family sans
-Help\SpecialChar \menuseparator
-About LyX
+Help\SpecialChar menuseparator
+About \SpecialCharNoPassThru LyX
\family default
.
All the rest of options passed to R are explained in the R script, and
- the LyX Customization manual also has detailed explanations about
+ the \SpecialCharNoPassThru LyX
+ Customization manual also has detailed explanations about
\family typewriter
$$i
\family default
\end_layout
\begin_layout Enumerate
-the encoding string of the LyX document is passed to R as an command line
+the encoding string of the \SpecialCharNoPassThru LyX
+ document is passed to R as an command line
option; possible values are
\family typewriter
ISO-8859-15
\begin_layout Enumerate
the R code chunks in the Sweave document are executed under the directory
- of the LyX document (if you are not sure, put
+ of the \SpecialCharNoPassThru LyX
+ document (if you are not sure, put
\family typewriter
getwd()
\family default
\end_layout
\begin_layout Enumerate
-if LaTeX cannot find
+if \SpecialCharNoPassThru LaTeX
+ cannot find
\family sans
Sweave.sty
\family default
, this R script will copy it to the temporary directory automatically where
- the LaTeX compilation takes place.
+ the \SpecialCharNoPassThru LaTeX
+ compilation takes place.
\end_layout
\begin_layout Enumerate
\end_inset
-) is that if the filename (without extension) contains dots, LaTeX can fail
+) is that if the filename (without extension) contains dots, \SpecialCharNoPassThru LaTeX
+ can fail
to deal with such files in
\family typewriter
\end_layout
\begin_layout Standard
-LyX can deal with the font encoding by default, so there is no need to ask
+\SpecialCharNoPassThru LyX
+ can deal with the font encoding by default, so there is no need to ask
Sweave to do this (furthermore, this may bring clashes of package options);
besides, the users can load the
\series bold
\end_layout
\begin_layout Standard
-Since LyX 2.0, we can see the detailed information during compilation via
+Since \SpecialCharNoPassThru LyX
+ 2.0, we can see the detailed information during compilation via
\family sans
-View\SpecialChar \menuseparator
+View\SpecialChar menuseparator
View Messages
\family default
.
- This is extremely helpful for trouble shooting -- the process of R will
+ This is extremely helpful for trouble shooting \twohyphens
+ the process of R will
be shown in the message panel, and we will be able to know which chunk
goes wrong in cases of errors.
For example, when you compile this document, you can see messages like
\begin_layout Standard
Another known issue is the Sweave code chunk may fail when we change the
- alignment of the chunk paragraph in LyX (using
+ alignment of the chunk paragraph in \SpecialCharNoPassThru LyX
+ (using
\family sans
Paragraph settings
\family default
-), because LyX may add a macro like
+), because \SpecialCharNoPassThru LyX
+ may add a macro like
\family typewriter
\backslash
must start in a new line with nothing before it.
Therefore we recommend you to double check the real source code via
\family sans
-View\SpecialChar \menuseparator
+View\SpecialChar menuseparator
View Source
\family default
when changing the alignment of a chunk paragraph, and make sure
\end_inset
.
- Questions about LyX and Sweave can be posted to the LyX mailing list (
+ Questions about \SpecialCharNoPassThru LyX
+ and Sweave can be posted to the \SpecialCharNoPassThru LyX
+ mailing list (
\begin_inset Flex URL
status collapsed
\end_inset
).
- More LyX examples are provided at
+ More \SpecialCharNoPassThru LyX
+ examples are provided at
\begin_inset Flex URL
status collapsed
\end_layout
\begin_layout Standard
-You will end up with LaTeX errors if you use Sweave in beamer slides in
- LyX; the reason is the beamer frame that contains verbatim R code and output
- must have the
+You will end up with \SpecialCharNoPassThru LaTeX
+ errors if you use Sweave in normal beamer slides
+ in \SpecialCharNoPassThru LyX
+; the reason is the beamer frame that contains verbatim R code.
+ The solution is to use a
+\emph on
+FragileFrame
+\emph default
+ instead of a normal
+\emph on
+Frame
+\emph default
+, or to pass the option
\family typewriter
fragile
\family default
- option.
- However, currently there is no straightforward way to do this.
- One way is to write raw TeX code, and the other is to use the
-\family sans
-beamer-fragile.module
-\family default
- discussed in
-\begin_inset CommandInset href
-LatexCommand href
-name "#7273"
-target "http://www.lyx.org/trac/ticket/7273"
-
-\end_inset
-
- (put this file under the
-\family sans
-layouts
-\family default
- directory of LyX user directory and reconfigure LyX).
- After including this module in your document, you should be able to use
-
+ to the frame title via
\family sans
-Insert\SpecialChar \menuseparator
-Custom Insets\SpecialChar \menuseparator
-FragileFrame
-\family default
-, which is essentially
-\family typewriter
-
-\backslash
-begin{frame}[fragile]
+Insert\SpecialChar menuseparator
+Frame Options
\family default
.
\end_layout
\emph default
(again, see
\family sans
-Help\SpecialChar \menuseparator
-About LyX
+Help\SpecialChar menuseparator
+About \SpecialCharNoPassThru LyX
\family default
).
- Note LyX will check the
+ Note \SpecialCharNoPassThru LyX
+ will check the
\emph on
user directory
\emph default
lyxsweave.R
\family default
is found in the user directory, it will be used.
- It is not recommended to hack the script under the LyX library directory
- directly, since updating LyX will override you modified script (the user
+ It is not recommended to hack the script under the \SpecialCharNoPassThru LyX
+ library directory
+ directly, since updating \SpecialCharNoPassThru LyX
+ will override you modified script (the user
directory will not be affected).
\end_layout