mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-23 18:24:48 +00:00
a33aa0632d
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@37220 a592a061-630c-0410-9148-cb99ea01b6c8
418 lines
5.4 KiB
Plaintext
418 lines
5.4 KiB
Plaintext
#LyX 2.0.0svn created this file. For more info see http://www.lyx.org/
|
|
\lyxformat 410
|
|
\begin_document
|
|
\begin_header
|
|
\textclass article
|
|
\use_default_options true
|
|
\begin_modules
|
|
sweave
|
|
\end_modules
|
|
\maintain_unincluded_children false
|
|
\language english
|
|
\inputencoding auto
|
|
\fontencoding global
|
|
\font_roman lmodern
|
|
\font_sans lmss
|
|
\font_typewriter lmtt
|
|
\font_default_family default
|
|
\use_non_tex_fonts false
|
|
\font_sc false
|
|
\font_osf false
|
|
\font_sf_scale 100
|
|
\font_tt_scale 100
|
|
|
|
\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 false
|
|
\use_amsmath 1
|
|
\use_esint 1
|
|
\use_mhchem 1
|
|
\use_mathdots 1
|
|
\cite_engine basic
|
|
\use_bibtopic false
|
|
\use_indices false
|
|
\paperorientation portrait
|
|
\suppress_date false
|
|
\use_refstyle 0
|
|
\index Index
|
|
\shortcut idx
|
|
\color #008000
|
|
\end_index
|
|
\secnumdepth 3
|
|
\tocdepth 3
|
|
\paragraph_separation skip
|
|
\defskip medskip
|
|
\quotes_language english
|
|
\papercolumns 1
|
|
\papersides 1
|
|
\paperpagestyle default
|
|
\tracking_changes false
|
|
\output_changes false
|
|
\html_math_output 0
|
|
\html_be_strict false
|
|
\end_header
|
|
|
|
\begin_body
|
|
|
|
\begin_layout Title
|
|
A Test File
|
|
\end_layout
|
|
|
|
\begin_layout Author
|
|
Friedrich Leisch
|
|
\begin_inset Foot
|
|
status collapsed
|
|
|
|
\begin_layout Plain Layout
|
|
LyX
|
|
\begin_inset Quotes eld
|
|
\end_inset
|
|
|
|
port
|
|
\begin_inset Quotes erd
|
|
\end_inset
|
|
|
|
by Gregor Gorjanc
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
A simple example that will run in any S engine: The integers from 1 to 10
|
|
are
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<print=TRUE>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
1:10
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<results=hide>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
print(1:20)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
@ % the above is just to ensure that 2 code chunks can follow each other
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
We can also emulate a simple calculator:
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<echo=TRUE,print=TRUE>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
1 + 1
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
1 + pi
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
sin(pi/2)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
@
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
Now we look at Gaussian data:
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
library(stats)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
x <- rnorm(20)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
print(x)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
print(t1 <- t.test(x))
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
@
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
Note that we can easily integrate some numbers into standard text: The third
|
|
element of vector
|
|
\family typewriter
|
|
x
|
|
\family default
|
|
is
|
|
\begin_inset Flex S/R expression
|
|
status collapsed
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
x[3]
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
, the
|
|
\begin_inset Formula $p$
|
|
\end_inset
|
|
|
|
-value of the test is
|
|
\begin_inset Flex S/R expression
|
|
status collapsed
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
format.pval(t1$p.value)
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
|
|
\family roman
|
|
\series medium
|
|
\shape up
|
|
\size normal
|
|
\emph off
|
|
\bar no
|
|
\noun off
|
|
\color none
|
|
Now we look at a summary of the famous iris dataset, and we want to see
|
|
the commands in the code chunks:
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
\begin_inset Flex Sweave Options
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
echo=true,keep.source=true
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<engine=R>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
# A comment
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
data(iris)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
summary(iris)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
@ % def
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
\begin_inset Float figure
|
|
placement tbph
|
|
wide false
|
|
sideways false
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
\noindent
|
|
\align center
|
|
\begin_inset ERT
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
<<fig=TRUE>>=
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
library(graphics)
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
pairs(iris)
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
@
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
\begin_inset Caption
|
|
|
|
\begin_layout Plain Layout
|
|
Pairs plot of the iris data.
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
\begin_inset Float figure
|
|
placement tbph
|
|
wide false
|
|
sideways false
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
\noindent
|
|
\align center
|
|
\begin_inset ERT
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
<<fig=true>>=
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
boxplot(Sepal.Length~Species,data=iris)
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
@
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
\begin_inset Caption
|
|
|
|
\begin_layout Plain Layout
|
|
Boxplot of sepal length grouped by species.
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
<<engine=S4>>=
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
function.that.comes.only.with.Splus(x)
|
|
\end_layout
|
|
|
|
\begin_layout Chunk
|
|
@
|
|
\end_layout
|
|
|
|
\begin_layout Standard
|
|
\begin_inset Float figure
|
|
wide false
|
|
sideways false
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
\noindent
|
|
\align center
|
|
\begin_inset ERT
|
|
status open
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
<<fig=true>>=
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
boxplot(Sepal.Length~Species,data=iris)
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
|
|
@
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\begin_layout Plain Layout
|
|
\begin_inset Caption
|
|
|
|
\begin_layout Plain Layout
|
|
Boxplot of sepal length grouped by species
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\end_inset
|
|
|
|
|
|
\end_layout
|
|
|
|
\end_body
|
|
\end_document
|