#LyX 1.4.3 created this file. For more info see http://www.lyx.org/ \lyxformat 245 \begin_document \begin_header \textclass literate-article \begin_preamble \SweaveOpts{echo=FALSE} \usepackage{a4wide} \end_preamble \options a4paper \language english \inputencoding latin1 \fontscheme default \graphics default \paperfontsize default \spacing single \papersize default \use_geometry false \use_amsmath 1 \cite_engine basic \use_bibtopic false \paperorientation portrait \secnumdepth 3 \tocdepth 3 \paragraph_separation skip \defskip medskip \quotes_language english \papercolumns 1 \papersides 1 \paperpagestyle default \tracking_changes false \output_changes true \end_header \begin_body \begin_layout Title A Test File \end_layout \begin_layout Author Friedrich Leisch \begin_inset Foot status collapsed \begin_layout Standard 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 Scrap <>= \newline 1:10 \newline <>= \newline print(1:20) \newline @ % 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 Scrap <>= \newline 1 + 1 \newline 1 + pi \newline sin(pi/2) \newline @ \end_layout \begin_layout Standard Now we look at Gaussian data: \end_layout \begin_layout Scrap <<>>= \newline library(stats) \newline x <- rnorm(20) \newline print(x) \newline print(t1 <- t.test(x)) \newline @ \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 ERT status open \begin_layout Standard \backslash Sexpr{x[3]} \end_layout \end_inset , the \begin_inset Formula $p$ \end_inset -value of the test is \begin_inset ERT status open \begin_layout Standard \backslash Sexpr{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 \family roman \series medium \shape up \size normal \emph off \bar no \noun off \color none \begin_inset ERT status open \begin_layout Standard \backslash SweaveOpts{echo=true} \end_layout \end_inset \end_layout \begin_layout Scrap <>= \newline data(iris) \newline summary(iris) \newline @ % def \end_layout \begin_layout Standard \begin_inset Float figure placement tbph wide false sideways false status collapsed \begin_layout Scrap \align center <>= \newline library(graphics) \newline pairs(iris) \newline @ \end_layout \begin_layout Caption Pairs plot of the iris data. \end_layout \end_inset \end_layout \begin_layout Standard \begin_inset Float figure placement tbph wide false sideways false status collapsed \begin_layout Scrap \align center <>= \newline boxplot(Sepal.Length~Species,data=iris) \newline @ \end_layout \begin_layout Caption Boxplot of sepal length grouped by species. \end_layout \end_inset \end_layout \begin_layout Scrap <>= \newline function.that.comes.only.with.Splus(x) \newline @ \end_layout \begin_layout Standard \begin_inset Float figure wide false sideways false status open \begin_layout Scrap \align center <>= \newline boxplot(Sepal.Length~Species,data=iris) \newline @ \end_layout \begin_layout Caption Boxplot of sepal length grouped by species \end_layout \end_inset \end_layout \end_body \end_document